Update configuration file to support different Go database drivers #473
Replies: 4 comments
-
|
|
Beta Was this translation helpful? Give feedback.
-
|
i get the attractiveness of making each of these their own separate object, but the nesting does make the config harder to read as a human. can the nesting be reduced without sacrificing too much flexibility? does the config need a |
Beta Was this translation helpful? Give feedback.
-
I'm not sure what choice we have. If (and when) pgx launches v5, there are going to be users that want to upgrade, and users that want to stay on v4.
If the only data we needed was driver and interface, sure. I'm imagining that each interface will eventually have its own configuration options. The reason I don't want to add driver as a top-level configuration is that it doesn't apply outside the context of the |
Beta Was this translation helpful? Give feedback.
-
Version 2 of the configuration file has a top-level gen section you can use. version: "2"
# Individual SQL packages
sql:
- queries: "query.sql"
schema: "schema.sql"
engine: "postgresql"
gen:
go:
package: "authors"
out: "."
# Defaults for all Go packages
gen:
go:
interface:
stdlib:
driver: "postgres" |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
sqlc has two versions of its configuration formats. Version 1 is widely used. Version 2 hasn't been, as it's only useful for people doing multi-language development. The proposed changes are backwards compatible for both versions.
A little bit of context: if you're using the
database/sqlpackage, you need to pick a driver for your database. When a driver is imported, it registers itself using sql.Register. As the docs say:It's also important to realize that pgx and other database drivers encourage users to avoid the
database/sqlpackage. As with all code generated by sqlc, this decision is left up to the user. Our design should support a future where sqlc can generate code using these alternative interfaces.Proposal
When the engine is
postgresql, valid values fordriverarepostgresandpgx.When the engine is
mysql, valid values fordriveraremysqlandgo-mysql.When we add support for using pgx directly, we'd add a new key to
interfaceAppendix
postgresqlpostgrespostgresqlpgxmysqlmysqlmysqlgo-mysqlsqlitesqlite3Related to #472
Beta Was this translation helpful? Give feedback.
All reactions