The default mapping of PostgreSQL/MySQL types to Go types only uses packages outside the standard library when it must.
For example, the
uuid PostgreSQL type is mapped to
If a different Go package for UUIDs is required, specify the package in the
overrides array. In this case, I’m going to use the
version: "2" sql: - schema: "postgresql/schema.sql" queries: "postgresql/query.sql" engine: "postgresql" gen: go: package: "authors" out: "postgresql" overrides: - db_type: "uuid" go_type: "github.com/gofrs/uuid.UUID"
Each mapping of the
overrides collection has the following keys:
In case the type overriding should be done on specific a column of a table instead of a type.
columnshould be of the form
table.columnbut you can be even more specific by specifying
catalog.schema.table.column. Can’t be used if the
db_typekey is defined.
A fully qualified name to a Go type to use in the generated code.
A reflect-style struct tag to use in the generated code, e.g.
a:"b" x:"y,z". If you want general json/db tags for all fields, use
true, use this type when a column is nullable. Defaults to
Note that a single
db_type override configuration applies to either nullable or non-nullable
columns, but not both. If you want a single
go_type to override in both cases, you’ll
need to specify two overrides.
When generating code, entries using the
column key will always have preference over
entries using the
db_type key in order to generate the struct.
For more complicated import paths, the
go_type can also be an object with the following keys:
The import path for the package where the type is defined.
The package name where the type is defined. This should only be necessary when your import path doesn’t end with the desired package name.
The type name itself, without any package prefix.
If set to
true, generated code will use pointers to the type rather than the type itself.
If set to
true, generated code will use a slice of the type rather than the type itself.
version: "2" sql: - schema: "postgresql/schema.sql" queries: "postgresql/query.sql" engine: "postgresql" gen: go: package: "authors" out: "postgresql" overrides: - db_type: "uuid" go_type: import: "a/b/v2" package: "b" type: "MyType" pointer: true