Hacker News new | ask | show | jobs
by bsaul 3291 days ago
compile-time code generation can only get you so far, unless you're ready to generate every single kind of query beforehand ( which grows exponentially with the number of -to-many relationship). You'll have to rely on introspection but i suspect things won't go smoothly.

anyway, it should make for a good exercise i'm sure.

as for the definition of Object-Relationnal-Mapper the idea is to completely abstract the fact that you're storing your object graph ( or struct graph in the case of go) in a relationnal database. To do so, the developper provides meta data , like an xml file or annotation, to describe the mapping. This is a pretty hard problem.

1 comments

It's not too difficult. Where I work, we're building a BI tool that maps domain concepts ("objects") to fields in relational databases (we're using Python and building out SQLAlchemy queries, but we're not doing anything that wouldn't easily translate into Go). The domain concepts are analogous to structs in Go or simple classes in Python. You only need to get the mapping data once (in our case, the user configures these mappings in the UI and then we load them at runtime, but these could come from anywhere) and from then on there is no magic.

If you know ahead of time what your types are, then you can do everything in code gen easily.

The tough bit is query optimization.