Database Destination
The Database destination writes processed messages to a relational database using parameterized SQL statements. It supports PostgreSQL, MySQL, and Microsoft SQL Server with connection pooling and environment-variable substitution for credentials.
Configuration
Section titled “Configuration”Add a Database destination to a channel in intu.yaml:
destinations: - name: patient-db type: database properties: driver: postgres dsn: "postgres://${DB_USER}:${DB_PASS}@db.hospital.local:5432/clinical?sslmode=require" statement: | INSERT INTO patients (mrn, first_name, last_name, dob) VALUES ($1, $2, $3, $4)Properties
Section titled “Properties”| Property | Type | Default | Description |
|---|---|---|---|
driver | string | (required) | Database driver: postgres, mysql, or mssql. |
dsn | string | (required) | Data source name (connection string). Supports ${VAR} substitution. |
statement | string | (required) | Parameterized SQL statement to execute for each message. |
max_conns | integer | 5 | Maximum number of open connections in the pool. |
max_idle_conns | integer | 2 | Maximum number of idle connections retained. |
conn_max_lifetime_ms | integer | 300000 | Maximum lifetime of a connection before it is closed and replaced (5 minutes default). |
DSN Format
Section titled “DSN Format”| Driver | Format | Example |
|---|---|---|
postgres | postgres://user:pass@host:port/dbname?sslmode=require | postgres://${DB_USER}:${DB_PASS}@db:5432/clinical?sslmode=require |
mysql | user:pass@tcp(host:port)/dbname?tls=true | ${DB_USER}:${DB_PASS}@tcp(db:3306)/clinical?tls=true |
mssql | sqlserver://user:pass@host:port?database=dbname&encrypt=true | sqlserver://${DB_USER}:${DB_PASS}@db:1433?database=clinical&encrypt=true |
Complete Example
Section titled “Complete Example”A Database destination that upserts patient records into PostgreSQL:
destinations: - name: patient-upsert type: database properties: driver: postgres dsn: "postgres://${DB_USER}:${DB_PASS}@db.hospital.local:5432/clinical?sslmode=require" statement: | INSERT INTO patients (mrn, first_name, last_name, dob, updated_at) VALUES ($1, $2, $3, $4, NOW()) ON CONFLICT (mrn) DO UPDATE SET first_name = EXCLUDED.first_name, last_name = EXCLUDED.last_name, dob = EXCLUDED.dob, updated_at = NOW() max_conns: 10 max_idle_conns: 3 conn_max_lifetime_ms: 600000