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.
TableModel
✓ import { TableModel } from 'pg-schemata'
✗ const { TableModel } = require('pg-schemata')
ESM-only; CommonJS require not supported. TypeScript types included.
SchemaDefinition
✓ import { SchemaDefinition } from 'pg-schemata'
✗ import SchemaDefinition from 'pg-schemata'
Named export, not default. Used for TypeScript schema type.
MigrationManager
✓ import { MigrationManager } from 'pg-schemata'
✗ const MigrationManager = require('pg-schemata').MigrationManager
ESM-only; class for programmatic migrations.
DatabaseError
✓ import { DatabaseError } from 'pg-schemata'
Exported error class for structured error handling.
pgSchemata default
✓ import * as pgSchemata from 'pg-schemata'
✗ import pgSchemata from 'pg-schemata'
No default export; use namespace import to access all exports.
Defines a table schema, creates a model extending TableModel, inserts a record, queries with WHERE modifiers, and demonstrates pagination and soft delete.
import pgp from 'pg-promise';
import { TableModel } from 'pg-schemata';
const db = pgp({ host: 'localhost', port: 5432, database: 'test', user: 'user', password: process.env.PGPASSWORD ?? '' });
const userSchema = {
dbSchema: 'public',
table: 'users',
columns: [
{ name: 'id', type: 'uuid', notNull: true },
{ name: 'email', type: 'text', notNull: true },
{ name: 'name', type: 'text', notNull: true },
],
constraints: { primaryKey: ['id'] },
};
class UserModel extends TableModel {
constructor() {
super(db, userSchema);
}
}
const userModel = new UserModel();
async function main() {
// Insert a user
const newUser = await userModel.insert({ id: 'uuid-1', email: 'test@example.com', name: 'Test' });
console.log('Inserted:', newUser);
// Find users with flexible WHERE
const users = await userModel.findWhere({ email: { $eq: 'test@example.com' } });
// Cursor-based pagination
const page = await userModel.findAllWithCursor({ limit: 10 });
// Soft delete (if softDelete enabled)
await userModel.removeWhere({ id: 'uuid-1' });
}
main().catch(console.error);
Errors
Common errors & fixes
Cannot find module 'pg-schemata'
pg-schemata not installed, or resolution issue in package.json/tsconfig
fixRun npm install pg-schemata pg-promise and ensure both are in dependencies.
Must use import to load ES Module: require() of ES Module not supported
Using CommonJS require() with ESM-only package
fixSwitch to import syntax: import { TableModel } from 'pg-schemata' pg-promise is not defined
pg-promise peer dependency not installed or not imported
fixInstall pg-promise: npm install pg-promise, then import it before using pg-schemata
Audit
Dependencies
pg-promiserequiredCore database interaction and connection management