3 ms·
How does it deal with mapping relationships? For example, a Many-to-Many between Posts and Tags, or a Many-to-One like Posts and Comments?
by jakearmitage 5y ago
How does it deal with mapping relationships? For example, a Many-to-Many between Posts and Tags, or a Many-to-One like Posts and Comments?
- scrubs 5y agoThat's pushing into full-on-ORM. I get the sense that these kind of transforms are not liked by this OP.
- LVB 5y agoRelationships are concern of the SQL you provide, not the tool's processing. It is really concerned with only: 1. the inputs used to execute a query 2. the type of output So whether your query is "SELECT * FROM comments" or "SELECT * FROM comments WHERE comments.postid=$1", the result is still []Comment.
- ethanpailes 5y agoIf you want a code generator like this that has support for that kind of thing, https://github.com/opendoor/pggen https://github.com/opendoor/pggen can automatically infer these kinds of relationships based on foreign key relationships and emit slices of pointers to connect the records together in memory. It can even figure out 1-1 relationships if there is a UNIQUE index on the foreign key. There is a little mini-DSL for specifying exactly how much of the transitive closure of a given record you want to get filled in for you.