The pgc.yaml file has three main option sections:
- version: configures the output generation version
- queries: configures how the query files will be found in the file system
- database: configures the database that will be used to prepare the queries
- codegen: configures the code generation.
Currently, the only value supported here is "1".
version: 1
Queries can either be a unix glob pattern or an array of patterns.
queries:
- 'queries/*.sql'Pgc uses pglite to run an in-memory postgres database. The pglite configuration accepts the following options:
database:
pglite:
username: postgres
database: postgres
extensions: # a mapping of extensions and their source
pg_trgm: "@electric-sql/pglite/contrib/pg_trgm"
# for more extensions see https://pglite.dev/extensions/When using an in-memory database, at least one database migration glob pattern must be defined.
database:
migrations:
- 'migrations/*.up.sql'Migrations will be run in alphabetical order.
Pgc also supports connecting to an external development database using a postgres dsn:
database:
url: postgres://postgres:password@127.0.0.1:5432/databaseIf the database url cannot be committed to version control, use an environment variable:
database:
url: $DATABASE_URLThe codegen section has the following arguments:
- target (required): A predefined target language and driver pair (e.g. "python:asyncpg")
- out (required): The output directory
- options (may be required): target specific options (e.g. python requires the
packageoption to be defined here.) - enums (optional): A list of table backed enums
- types (optional): A list of type annotation overrides
- exclude_tables: A list of tables to exclude from modeling
codegen:
target: python:asyncpg
out: ./app/queries
enums:
- genre
types:
pg_catalog.json:
name: dict
pg_catalog.geometry:
name: shapely.Geometry
annotation: shapely.Geometry
import: shapely
options:
package: app.queries
exclude_tables:
- logsAsyncpg has some limitations to what fields models can have when setting a type codec. For example, a table containing a jsonb field cannot be decoded into a custom class.
This is addressed by excluding the table from the generation.