@spinajs/orm-postgres
v2.0.543
Published
orm postgresql integration
Maintainers
Readme
@spinajs/orm-postgres
PostgreSQL driver for the SpinaJS ORM.
Usage
import { Configuration } from '@spinajs/configuration';
// connection configuration
{
db: {
Connections: [
{
Driver: 'orm-driver-postgres',
Name: 'default',
Host: 'localhost',
Port: 5432,
User: 'postgres',
Password: 'postgres',
Database: 'app',
Options: {
// optional: pins search_path for every pooled connection; also the schema
// tableInfo() reads from. Defaults to `public`.
Schema: 'public',
},
},
],
},
}Dialect notes — differences from the shared @spinajs/orm-sql (MySQL-flavoured) layer
| Feature | MySQL / shared layer | This driver |
| --- | --- | --- |
| Identifier quoting | `backticks` | "double quotes" |
| Bound parameters | ? | rewritten to $1..$n at execution |
| Generated keys | LAST_INSERT_ID() | RETURNING rows (insertReturning: true) |
| Auto increment | AUTO_INCREMENT, NULL in VALUES assigns the key | GENERATED BY DEFAULT AS IDENTITY, DEFAULT in VALUES assigns the key |
| Upsert | ON DUPLICATE KEY UPDATE c = VALUES(c) | ON CONFLICT (cols) DO UPDATE SET c = EXCLUDED.c |
| Insert-or-ignore | INSERT IGNORE | ON CONFLICT DO NOTHING |
| Offset without limit | LIMIT 18446744073709551615 | bare OFFSET |
| ENUM / SET columns | native types | TEXT (+ CHECK (col IN (...)) for enum) |
| DATETIME / DOUBLE / BLOB / JSON | native names | TIMESTAMP / DOUBLE PRECISION / BYTEA / JSONB |
| UNSIGNED, per-column CHARACTER SET, inline COMMENT | supported | dropped (no postgres spelling) |
| MODIFY column | one clause restates the column | ALTER COLUMN ... TYPE / SET / DROP actions, MODIFY semantics kept (omitted NOT NULL / DEFAULT is dropped) |
| CREATE DATABASE IF NOT EXISTS | supported | refused — postgres has no such clause |
| CREATE EVENT, table history triggers, CREATE TABLE ... LIKE | MySQL syntax | unregistered — fail with a DI error naming the abstraction |
| DECIMAL / NUMERIC / BIGINT in responses | driver-dependent | strings (node-postgres refuses to lose precision above 2^53); ResponseSchemaTypes says so |
Transactions run on a dedicated pooled client with full savepoint support; all four
standard isolation levels are accepted (READ UNCOMMITTED behaves as READ COMMITTED,
postgres' documented, standard-permitted upgrade).
Running integration tests
The integration suite expects the docker fixture from the repository root:
docker compose --profile test up -d postgresIt listens on port 15432 by default; override with ORM_TEST_POSTGRES_PORT.
