Registry / database / postgres-pdo

postgres-pdo

JSON →
library0.1.3jsnpmunverified

Postgres Data Objects (PDO) is a lightweight TypeScript-first ORM for PostgreSQL that provides a clean, class-based interface for database operations. Current stable version is 0.1.3. It focuses on type safety and developer experience by leveraging TypeScript generics for compile-time query validation. Key differentiators include automatic schema inference from database tables, built-in migration support, and zero-configuration setup for common use cases. Unlike heavier ORMs like TypeORM or Prisma, PDO aims to be minimal with no external runtime dependencies beyond the 'pg' driver. Release cadence is irregular as it is still in early development.

npm install postgres-pdo
INSTALL
IMPORT
SIG · POSTGRES-PDO
P
postgres-pdo
databasejavascriptv0.1.3
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

PDO
import { PDO } from 'postgres-pdo'
const PDO = require('postgres-pdo')
ESM-only; CommonJS require() will fail. Use dynamic import or ES modules.
Model
import { Model } from 'postgres-pdo'
import Model from 'postgres-pdo'
Model is a named export, not default. Default import is undefined.
Table
import { Table } from 'postgres-pdo'
Named export. Used to define table metadata.

Connect to a PostgreSQL database, define a User model with a table decorator, and query users by name pattern.

import { PDO, Model, Table } from 'postgres-pdo'; const pdo = new PDO({ host: 'localhost', port: 5432, database: 'mydb', user: 'user', password: process.env.DB_PASSWORD ?? '' }); @Table({ name: 'users' }) class User extends Model { id!: number; name!: string; email!: string; } async function main() { await pdo.connect(); const users = await User.query().where('name', 'like', '%John%').get(); console.log(users); await pdo.disconnect(); } main();
Debug
Known issues
breakingIn v0.1.0, the query builder 'where' method changed signature from .where('name', 'John') to .where('name', '=', 'John'). Old syntax silently ignores operator.
fix
Update all .where() calls to include operator as second argument: .where('field', '=', 'value')
affects: <0.1.0
breakingPDO constructor options property 'password' renamed to 'pwd' in v0.1.2. Using 'password' throws error.
fix
Use 'pwd' instead of 'password' in connection config: { ..., pwd: 'secret' }
affects: >=0.1.2
deprecatedMethod 'Model.all()' is deprecated and will be removed in v1.0.0. Use 'Model.query().get()' instead.
fix
Replace Model.all() with Model.query().get()
affects: >=0.1.0
gotchaIf you do not call await pdo.connect() before querying, the library will try to auto-connect, but may fail silently in some environments.
fix
Always call await pdo.connect() at startup and await pdo.disconnect() when done.
affects: all
gotchaDefining model properties without TypeScript `!` (definite assignment) emits strictPropertyInitialization error. Package expects fields to be declared with `!` or initialized explicitly.
fix
Add exclamation marks: id!: number; or use constructor to initialize.
affects: all
breakingIn v0.1.1, the import path for TypeScript types changed from 'postgres-pdo/types' to 'postgres-pdo' (types are now bundled).
fix
Remove imports from 'postgres-pdo/types'; all types are now exported from main package.
affects: >=0.1.1
deprecatedThe 'raw' query method is deprecated since v0.1.3. Use the query builder instead for better type safety.
fix
Replace pdo.raw(sql) with Model.query().raw(sql) or use the query builder methods.
affects: >=0.1.3
Errors
Common errors & fixes
Error: Password must be a string
Using the old 'password' property in PDO config after v0.1.2
fix
Change config key from 'password' to 'pwd'
SyntaxError: The requested module 'postgres-pdo' does not provide an export named 'default'
Using default import instead of named import
fix
Use import { PDO } from 'postgres-pdo' instead of import PDO from 'postgres-pdo'
TypeError: Model.query is not a function
Forgetting to extend the Model class, or missing @Table decorator
fix
Ensure your class extends Model and has @Table decorator: class User extends Model { ... }
Error: Connection refused. Is the server running on host 'localhost' and accepting TCP/IP connections on port 5432?
PostgreSQL server not running or wrong host/port
fix
Ensure PostgreSQL is started and connection settings are correct. Use environment variables for host, port.
Property 'id' has no initializer and is not definitely assigned in the constructor.
TypeScript strict mode requires definite assignment assertion for model properties
fix
Add ! to property declaration: id!: number;
Upgrade
Version history
0.1.3latest on npm
Audit
Dependencies
pgrequiredPostgreSQL client driver required for database connections
Agent activity
7 hits · last 30 days
node
6
Resources
postgres-pdo — npm install postgres-pdo · libregistry