Postgres
how to configure preen to connect to Postgres databases.
Preen uses the pgx library to connect to Postgres databases.
Example Preen Source Configuration
# FILENAME: ~/.preen/sources.yaml
sources:
- name: postgres-example
engine: postgres
connection:
host: localhost
port: 5432
database: postgres
username: ${PG_USER} # You can specify environment variables in the sources.yaml file.
password: ${PG_PASSWORD}
Postgres Models
Postgres models are defined as a YAML file that contains a SQL query.
# FILENAME: ~/.preen/models/users.yaml
name: users # This name needs to be unique
type: sql
query: |
select
users.id,
users.first_name,
users.last_name,
users.birthday
from
users;
Postgres Type Mappings
A comprehensive list of Postgres type mappings can be found here. We use the pgtype library to map Postgres types to Go types, with a few custom mappings for things like float64
, duration
, and time
types.
Code References
Last updated