Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load engine-dependent queries #5

Open
qustavo opened this issue Nov 24, 2014 · 7 comments
Open

Load engine-dependent queries #5

qustavo opened this issue Nov 24, 2014 · 7 comments

Comments

@qustavo
Copy link
Owner

qustavo commented Nov 24, 2014

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 :)

@hxzhao527
Copy link
Contributor

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.

@qustavo
Copy link
Owner Author

qustavo commented Oct 22, 2018

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

@hxzhao527
Copy link
Contributor

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

@qustavo
Copy link
Owner Author

qustavo commented Oct 30, 2018

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
Copy link
Owner Author

qustavo commented Oct 30, 2018

Also, how should the API look like?

@hxzhao527
Copy link
Contributor

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).

@qustavo
Copy link
Owner Author

qustavo commented Nov 13, 2018

I like it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants