Postgres adapter
The Postgres adapter introspects via pg_catalog system tables and produces SQL with $1, $2, ... positional parameters and double-quoted identifiers.
Setup
import pg from 'pg';
import { Biref, postgresAdapter } from '@biref/scanner';
const client = new pg.Client({ connectionString: 'postgres://localhost/mydb' });
await client.connect();
const biref = Biref.builder()
.withAdapter(postgresAdapter.create(client))
.build();
Client interface
postgresAdapter.create() accepts any object matching this structural type:
interface PostgresClient {
query<TRow>(
text: string,
params?: readonly unknown[],
): Promise<{ rows: TRow[] }>;
}
Both pg.Client and pg.Pool satisfy this shape. The SDK never imports pg.
Namespace model
Postgres uses schemas as namespaces. Default: public.
// Scan specific schemas
const model = await biref.scan({ namespaces: ['public', 'auth', 'billing'] });
// Scan everything (excludes pg_catalog, information_schema, pg_toast*, pg_temp_*)
const model = await biref.scan({ namespaces: 'all' });
URL schemes
postgres, postgresql
Type mapping
| Postgres type | Category |
|---|---|
| int2, int4, int8, serial, bigserial | integer |
| numeric, decimal, real, float4, float8, money | decimal |
| text, varchar, char, citext, name | string |
| bool, boolean | boolean |
| date | date |
| timestamp, timestamptz | timestamp |
| time, timetz | time |
| json, jsonb | json |
| uuid | uuid |
| bytea | binary |
| custom enum types | enum |
| any[] | array (with recursive elementType) |
Record parser
PostgresRecordParser extends DefaultRecordParser with:
int8/bigintstrings converted to JSbigintjson/jsonbstrings parsed to objects- All other categories fall through to the default parser
Indexes
Supports: btree, hash, gin, gist, brin, spgist. Partial indexes are detected.
Constraints
Supports: unique, check, exclusion.