Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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?


Relationships 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.


If you want a code generator like this that has support for that kind of thing, 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.


That's pushing into full-on-ORM. I get the sense that these kind of transforms are not liked by this OP.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: