Your Question

Hello, we encountered one use case where we want to change the dialector temporarily with dbresolver along with conn pool.

We use our DataLake SQL driver with gorm. We have created a custom dialector for it already implementing the required interface.

But the application's primary DB is MySQL and for only a few queries, we want to switch to the DataLake connection. We thought of using dbresolver plugin. But since internally it's not changing the dialector hence, an incorrect quote is used in our datalake queries (` instead "). (This is because the statement calls QuoteTo function on dialector only) We tried writing our own plugin as well (derived from dbresolvers plugin) and in the code where we switch the conn pool, we tried switching the dialector as well.

db.Statement.Dialector = plugin.dialector
db.Statement.ConnPool = plugin.connPool

The issue with this approach in the statement dialector is not reverted to the original dialector like conn pool is for other queries, and in the subsequent queries, we are seeing data lake's dialector is used instead MySQL one.

our question is, what is the correct way to change the dialector for one query when using dbresolver?

The document you expected this should be explained

Expected answer

Comment From: a631807682

If you just want to change the behavior of QuoteTo, you can record the current database type in plugin.dialector and implement the QuoteTo interface. Other behaviors can be similar to the dbresolver plugin.

Comment From: charlie1404

you can record the current database type in plugin.dialector and implement the QuoteTo interface

We tried that, but the problem is internally gorm does not call it, it's still calling the quote.to on MySQL dialector.