Licence
MIT
Version
0.2.1
Deps
1
Size
30 kB
Vulns
0
Weekly
11
@xfcfam/xf-sql-postgres
PostgreSQL dialect adapter for
@xfcfam/xf-sql— Kysely'sPostgresDialectoverpg, plus the SQLSTATE → typed-Exception translation, so the Business Layer never seespgerrors.
pgandkyselyare bundled and wired internally — the adapter builds thepg.Pooland the dialect in its constructor. You never install or import either.
Install
npm i @xfcfam/xf @xfcfam/xf-sql @xfcfam/xf-sql-postgresQuick start
import { PostgresDatabaseRepository } from '@xfcfam/xf-sql-postgres'
import { UniqueViolationException } from '@xfcfam/xf-sql'
export class UsersDb extends PostgresDatabaseRepository<Schema> {
constructor() { super({ connectionString: process.env.DATABASE_URL!, pool: { max: 10 } }) }
createUser(input: NewUser) {
return this.exec(() =>
this.db.insertInto('users').values(input).returningAll().executeTakeFirstOrThrow())
}
}Exported Components
Generalizations
| Component | Description |
|---|---|
PostgresDatabaseRepository<Schema> |
Extends TransactionalDatabaseRepository; wires PostgresDialect + pg.Pool from PostgresOptions (connectionString + optional pool). Its translateError maps pg SQLSTATEs to the @xfcfam/xf-sql exceptions. |
Utilities
| Component | Description |
|---|---|
PostgresErrorUtils |
Maps any pg / Kysely error to the matching @xfcfam/xf-sql exception. |
SQLSTATE mapping —
23505→UniqueViolation,23503→ForeignKeyViolation,23514→Check,23502→NotNull,40P01→Deadlock, transport codes →Connection.table/column/constraintare forwarded onto the exception.
Documentation
Full specification → xfcfam.org · SQLSTATE codes
License
MIT