Replies: 2 comments
-
sqlc will generate a constructor that takes a *sql.DB struct and returns a *Queries struct. type DBTX interface {
ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
PrepareContext(context.Context, string) (*sql.Stmt, error)
QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
QueryRowContext(context.Context, string, ...interface{}) *sql.Row
}
func New(db DBTX) *Queries {
return &Queries{db: db}
} You would need to call this constructor with both of your database connections.
sqlc supports this, but it may not work as you expect. sqlc isn't doing any translation of the SQL you right, so you have to make sure that your SQL queries work with MySQL and PostgreSQL, which can be challenging. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Got it. Thanks for the explanation. Sent from my Galaxy
-------- Original message --------From: Kyle Conroy <[email protected]> Date: 2/23/21 10:25 PM (GMT-07:00) To: kyleconroy/sqlc <[email protected]> Cc: jzendle <[email protected]>, Author <[email protected]> Subject: Re: [kyleconroy/sqlc] support for mutiple db connections (#908)
Does sqlc support multiple connections to different instances of mysql (just mysql)?
sqlc will generate a constructor that takes a *sql.DB struct and returns a *Queries struct.
type DBTX interface {
ExecContext(context.Context, string, ...interface{}) (sql.Result, error)
PrepareContext(context.Context, string) (*sql.Stmt, error)
QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error)
QueryRowContext(context.Context, string, ...interface{}) *sql.Row
}
func New(db DBTX) *Queries {
return &Queries{db: db}
}
You would need to call this constructor with both of your database connections.
How about multiple connections to a mix of mysql and PG?
sqlc supports this, but it may not work as you expect. sqlc isn't doing any translation of the SQL you right, so you have to make sure that your SQL queries work with MySQL and PostgreSQL, which can be challenging.
—You are receiving this because you authored the thread.Reply to this email directly, view it on GitHub, or unsubscribe.
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
Nice work!
2 quick questions:
I have an application that must connect to multiple databases. Could be mysql and/or PG
Thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions