Diesel-builders: a type-safe builder pattern library for Diesel that handles complex table relationships. #4891
LucaCappelletti94
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I have been working on a crate called diesel-builders.
It provides a type safe builder pattern for Diesel that helps insert data across related tables, including complex insert operations like DAGs and tables with mandatory or discretional triangular dependencies. Once the necessary schema traits are implemented, quite complex insert queries can be carried out knowing that the insert order, the tables relationships and all associated setter methods will be guaranteed to be correct at compile time.
Here follows an example of a rather complex query to write by hand: tables forming an inheritance DAG.
Tables A, is extended by table B and C.
Table D extends both B and C.
The following insert operation inserts first A, then populates the primary keys of the dependant tables B, C and D, then inserts B, C and finally D.
At this time, the builder supports:
These patterns are described with diagrams in the README.
I would appreciate any feedback, thank you for taking a look. The
diesel-builderscrate contains several things which I believe may be better positioned in diesel, such as theForeignKeyandTableIndextraits and macros.Best,
Luca
Beta Was this translation helpful? Give feedback.
All reactions