go-gorm / gorm

The fantastic ORM library for Golang, aims to be developer friendly
https://gorm.io
MIT License
36.87k stars 3.93k forks source link

Extracting query builder to separate project #1115

Closed mex closed 6 years ago

mex commented 8 years ago

I recently had to make a more robust migration setup and because I'm using Gorm, I tried to be consistent in the query generation and dialects (my setup has to support SQLite, MySQL, and Postgres without too much hassle), so I hooked into the dialects of Gorm and copied a lot of schema generation code from the scope file.

In that context it would really be nice to be able to hook into the query builder directly and get both the schema generation and the dialect support, which would be very easy to do, if the query builder and dialect support was in a separate project.

As far as I could see, when a dove into the code, the query generation parts are already pretty isolated from the ORM part, so it shouldn't be an impossible project, and I'm interested in contributing some time to do this, but I would like to hear, whether @jinzhu is interested in having this separation.

Looking forward to hearing some feedback.

jinzhu commented 7 years ago

Hi @mex

Do you want to get the generated SQL? what's your expected API for this?

mex commented 7 years ago

The parts I needed the most was the dialect transformations like quoting table names or fields and translating Go types to field types.

Extracting that specific functionality, so you had some kind of dialect transformer, would be the most interesting. Currently I've mimicked a lot of the internal Gorm stuff and then hooked deep into it some other places.

jinzhu commented 6 years ago

There are many functions already extracted to Dialect's method, will keep extracting more methods to Dialect in v2.