dotsql
dotsql copied to clipboard
Load engine-dependent queries
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 :)
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.
that might work :+1: . How would you handle duplication, to avoid repeating :name
twice
emmm, in mybatis from Java, duplication will cause runtime-exception. I think panic
is proper for duplication when init Dotsql.
my point is, how can u define the same operation insert-user
with 2 different queries, one per engine without duplicating :name
and :doc
Also, how should the API look like?
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)
.
I like it