izumin5210 / grapi

😮 A surprisingly easy API server and generator in gRPC and Go
https://godoc.org/github.com/izumin5210/grapi/pkg/grapiserver
MIT License
424 stars 39 forks source link

proposal: gen the DB #157

Open ghost opened 5 years ago

ghost commented 5 years ago

THis is a really great project. I have been working on something similar, but i think i will swap to yours.

I was wondering if you think using sqlboiler ( github.com/volatiletech/sqlboiler ) to gen the DB makes sense ? I noticed that you gen the Standard CRUD Methods and so it seems a pretty good idea to then do the same for the DB.

There is always a imbalance, for want of a better word, between what your DB model looks like and what your GRPC model looks like. Hope you know what i mean ? SO for now, if you think this is a good idea, then the developer has to write code in the middle to get the data from the DB that he / she needs to fulfil the Protobuf API.

In the past i wrote a very large code generator that is quite a bit like this. In order to help with the "imbalance" we created a mapping between the protobuf and the db tables, to help do more codegen. But i think thats much later..

anyways, eager to hear what your think.

fi0 commented 5 years ago

something similar to https://github.com/infobloxopen/protoc-gen-gorm but for sqlboiler instead of gorm?

l4u commented 5 years ago

It would be nice for a grapi db plugin. This shouldn't be added in the grapi core to avoid bloats.

ghost commented 5 years ago

@fi0 yes exactly. github.com/volatiletech/sqlboiler is much faster since it does not use reflection. The benchmarks show a 5 to 10 times speed up https://github.com/volatiletech/sqlboiler#benchmarks

@l4u makes sense. SQL boiler is a db schema first generator. I think we can gen the schema from the protobufs but not sure right now. any ideas ? EDIT: just saw that https://github.com/infobloxopen/protoc-gen-gorm uses meta data added to the protobufs to infer the database. Seems very smart as i like the idea of it all being in the protobufs. Is this a problem for grapi ?