在Golang中如何支持多种SQL语法(MySQL vs Postgres)

My go app shall support multiple databases. Meaning, running the same binary with different databases, the database the app is working with will be determined by configuration.

The problem is, each database has it's own prepared statements syntax. Example:

db.Prepare("select p, f, t from mytable where p = $1") 

Will work for postgres but will not work for mysql.

db.Prepare("select p, f, t from mytable where p = ?") 

Will work for mysql but will not work for postgres.

Off curse I can solve it by editing the string on runtime or maintaining multiple queries.

Is there a better way?

I do not want to have some huge abstraction with an external library that will take control on all my db access, but if there is some light weight library that just magically fix the syntax, I am good with that.

EDIT: Summarising what I have said before, the part that bothers me is that for mysql you will have to use "?" while for postgres you will have to use $1, $2...

Cheers

In this particular case use a place holder {{ph}} in the end of the SQL and use strings.Replace() to replace it with ? Or $1 according to the db driver.