make generic DB implementation using macros... or ??? #3

Closed
opened 2025-04-22 08:52:17 +00:00 by despiegk · 3 comments
Owner

see heromodels

make work for /Users/despiegk/code/git.ourworld.tf/herocode/db/heromodels/src/herodb = ourdb + tss
but also for other db Fjall

binary encoding

a performance test

see heromodels make work for /Users/despiegk/code/git.ourworld.tf/herocode/db/heromodels/src/herodb = ourdb + tss but also for other db Fjall binary encoding a performance test
lee was assigned by despiegk 2025-04-22 08:52:17 +00:00
Author
Owner

branch db2

branch db2
Member

Pushed new branch https://git.ourworld.tf/herocode/db/src/branch/alternative_db_interface, which contains an altenrative implementation of DB (generic trait which can be implemented by multiple different backends if needed), and an implementation for OurDB + TST. The implementations uses generics to specify collections at compile time. Also added an Index trait linked to model implementations, which can be implemented on marker structs to specify index fields when doing get/delete operations. This could be extended to a procedural macro to auto generate the implementation of index marker structs if needed.

One issue in this implementation is that ourdb currently does not seem to support different keyspaces, so the object ID is shared between all different model types, and updating an object with one of a different type causes an error.

Pushed new branch https://git.ourworld.tf/herocode/db/src/branch/alternative_db_interface, which contains an altenrative implementation of DB (generic trait which can be implemented by multiple different backends if needed), and an implementation for OurDB + TST. The implementations uses generics to specify collections at compile time. Also added an Index trait linked to model implementations, which can be implemented on marker structs to specify index fields when doing get/delete operations. This could be extended to a procedural macro to auto generate the implementation of index marker structs if needed. One issue in this implementation is that ourdb currently does not seem to support different keyspaces, so the object ID is shared between all different model types, and updating an object with one of a different type causes an error.
Member
  • Separated the core types into a crate heromodels_core. This is needed to allow procedural macro to work in any crate (both in heromodels itself, as well as potential other crates).
  • Created a heromodels_derive crate which exposes a model procedural macro. This macro can be applied to structs to automatically generate the Model implementation and the index implementations. #[index] attributes can be applied to the required fields. The index markers are genrated in a public submodule to avoid name collisions, since the markers are generated snake case (to match the field declerations)
  • Reworked the DB to simplify its constructor
  • Also reworked get/delete methods generics to handle a bit better.

The User and Comment implementation are updated to now use the procedural macro.
Check heromodels/example/basic_user_example.rs to see how to use it as a client
Check heromodels/src/models/userxample/user.rs to see the macro (or the new examples)

All on branch alternative_db_implementation

- Separated the core types into a crate `heromodels_core`. This is needed to allow procedural macro to work in any crate (both in heromodels itself, as well as potential other crates). - Created a `heromodels_derive` crate which exposes a `model` procedural macro. This macro can be applied to structs to automatically generate the `Model` implementation and the index implementations. `#[index]` attributes can be applied to the required fields. The index markers are genrated in a public submodule to avoid name collisions, since the markers are generated snake case (to match the field declerations) - Reworked the DB to simplify its constructor - Also reworked get/delete methods generics to handle a bit better. The User and Comment implementation are updated to now use the procedural macro. Check heromodels/example/basic_user_example.rs to see how to use it as a client Check `heromodels/src/models/userxample/user.rs` to see the macro (or the new examples) All on branch alternative_db_implementation
Sign in to join this conversation.
No Label
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: herocode/db#3
No description provided.