dotsql icon indicating copy to clipboard operation
dotsql copied to clipboard

Load engine-dependent queries

Open qustavo opened this issue 10 years ago • 7 comments

So let's say we have set of queries that we know are able to run on mysql/postgres/sqlite3. But we also have queries that uses specific engine extensions. So I'm looking for a confortable way to implement this, I'm not sure if an extra tag (@krisajenkins?) is the right way to do it, or expose a DotSql.Merge() method that allows to add more queries to the actual loader. Ideas will be appreciated :)

qustavo avatar Nov 24 '14 09:11 qustavo

The style of hugsql seems good. For example,

-- :name insert-user
-- :doc Insert one user
-- :type mysql
insert into user (name, email) values (?, ?)
-- :name insert-user
-- :doc Insert one user
-- :type pg
insert into user (name, email) values ($, $)

I thnk Adding extra tags to instruct which db it is for is a good way.

hxzhao527 avatar Oct 20 '18 06:10 hxzhao527

that might work :+1: . How would you handle duplication, to avoid repeating :name twice

qustavo avatar Oct 22 '18 06:10 qustavo

emmm, in mybatis from Java, duplication will cause runtime-exception. I think panic is proper for duplication when init Dotsql.

hxzhao527 avatar Oct 25 '18 10:10 hxzhao527

my point is, how can u define the same operation insert-user with 2 different queries, one per engine without duplicating :name and :doc

qustavo avatar Oct 30 '18 09:10 qustavo

Also, how should the API look like?

qustavo avatar Oct 30 '18 09:10 qustavo

Every engine has its own queries map. Only one per name is allowed for one engine.

dotsql.MySQL().Get("name")

Also, we can set the default engine. So

dotsql.Default("mysql")
dotsql.Get("name")

will work too.

If integrated with sqlx, we can supply a rebind method, just like dotsql.Get("name").Rebind(other engine).

hxzhao527 avatar Nov 13 '18 00:11 hxzhao527

I like it

qustavo avatar Nov 13 '18 09:11 qustavo