Registry / database / 5no-pg-model

5no-pg-model

JSON →
library1.3.1jsnpmunverified

A JavaScript ORM for PostgreSQL that provides a declarative schema definition, automatic query building, and relation handling including one-to-one, one-to-many, and join relationships. Version 1.3.1 is the last release under the 5no-pg-model package; it has been renamed to @5no/pg-model. The library supports Node 8+ and uses @5no/pg-builder for query generation and @5no/schema for schema validation. It offers auto-filling fields for created/updated timestamps, cascade operations on relations, and a Manager for CRUD operations. Differentiates from heavier ORMs like Sequelize by being lightweight and focused on PostgreSQL only, with a minimal API surface.

npm install 5no-pg-model
INSTALL
IMPORT
SIG · 5NO-PG-MODEL
5
5no-pg-model
databasejavascriptv1.3.1
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.

Manager
const { Manager } = require('@5no/pg-model')
const Manager = require('5no-pg-model').Manager
Package renamed; use @5no/pg-model. CommonJS only; no ESM exports.
Model
const { Model } = require('@5no/pg-model')
import { Model } from '@5no/pg-model'
No ESM support; must use require.
Builder
const Manager = require('@5no/pg-model').Manager; const builder = Manager.build(ModelInstance).builder()
const { Builder } = require('@5no/pg-model')
Builder is not directly exported; access via Manager.build().builder().

Connects to PostgreSQL, defines a User model with auto-timestamp columns, creates a new user, and outputs its JSON representation.

const { Manager, Model } = require('@5no/pg-model'); class User extends Model { static schema = { table: { schema: 'public', name: 'users' }, columns: { id: { type: String, primaryKey: true, defaultValue: null }, name: { type: String, defaultValue: null }, email: { type: String, required: true }, created_at: { type: Date, created: true, format: 'YYYY-MM-DD HH:mm:ss' }, updated_at: { type: Date, updated: true, format: 'YYYY-MM-DD HH:mm:ss' }, }, relations: {}, }; } async function main() { await Manager.init(); // connect using DATABASE_URL env var const user = new User(); user.setData({ name: 'John', email: 'john@example.com' }); await user.save(); console.log(await user.toJSON()); } main().catch(console.error);
Debug
Known issues
breakingPackage renamed from 5no-pg-model to @5no/pg-model. All imports must use @5no/pg-model.
fix
Change require('5no-pg-model') to require('@5no/pg-model').
affects: >=1.0.0
deprecated5no-pg-model is deprecated; only @5no/pg-model receives updates.
fix
Migrate to @5no/pg-model.
affects: >=1.0.0
gotchaNo ESM support (import/export). Must use CommonJS require.
fix
Use require() instead of import.
affects: >=1.0.0
gotchaManager.init() uses DATABASE_URL environment variable by default; no explicit connection config method.
fix
Set DATABASE_URL or pass options to Manager.init() if available.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module '5no-pg-model'
Trying to import the old package name.
fix
npm install @5no/pg-model and require('@5no/pg-model')
TypeError: Manager.build(...).builder is not a function
Incorrect usage of Manager.build; builder() is called on the result of Manager.build()
fix
Manager.build(User).builder() instead of Manager.build(User.builder())
Upgrade
Version history
1.3.1latest on npm
Audit
Dependencies
@5no/pg-builderrequiredQuery building engine
@5no/schemarequiredSchema definition and validation
Agent activity
77 hits · last 30 days
node
70
Perplexity
1
OpenAI (training)
1
Resources
5no-pg-model — npm install 5no-pg-model · libregistry