{"id":43689,"library":"postgresorm","title":"PostgresORM","description":"PostgresORM is a minimalistic ORM for PostgreSQL, version 5.1.1. It provides basic CRUD operations, pagination, transactions, and custom query support with parameterized queries. Designed for simplicity, it uses a connection pool and requires manual release of database contexts. The library has low activity and is not actively maintained. It differentiates by offering a lightweight alternative to full-featured ORMs like Sequelize or TypeORM, but lacks advanced features like migrations, model definitions, or TypeScript support.","status":"maintenance","version":"5.1.1","language":"javascript","source_language":"en","source_url":"https://github.com/littlezigy/postgresorm","tags":["javascript","orm","postgresql","postgres","database"],"install":[{"cmd":"npm install postgresorm","lang":"bash","label":"npm"},{"cmd":"yarn add postgresorm","lang":"bash","label":"yarn"},{"cmd":"pnpm add postgresorm","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"PostgreSQL client driver used for database connections and pool management.","package":"pg","optional":false}],"imports":[{"note":"initializeDatabase is a named export, not a default one.","wrong":"const initializeDatabase = require('postgresorm');","symbol":"initializeDatabase","correct":"const { initializeDatabase } = require('postgresorm');"},{"note":"db is a function, so it must be invoked as db() to get the database context.","wrong":"const db = require('postgresorm').db;","symbol":"db","correct":"const { db } = require('postgresorm');"},{"note":"pool is the underlying pg.Pool instance, accessible as a named export.","wrong":"const pool = require('postgresorm').pool;","symbol":"pool","correct":"const { pool } = require('postgresorm');"}],"quickstart":{"code":"const { initializeDatabase, db, pool } = require('postgresorm');\n\nconst config = {\n  connectionString: process.env.DATABASE_URL ?? 'postgres://username:password@localhost:5432/mydb',\n  max: 10,\n  idleTimeoutMillis: 30000,\n};\n\ninitializeDatabase(config);\n\nasync function run() {\n  const client = await pool.connect();\n  const database = db(client);\n\n  try {\n    // Create a record\n    const newUser = await database.create('users', { name: 'Alice', email: 'alice@example.com' });\n    console.log('Created user:', newUser);\n\n    // List records\n    const users = await database.list('users');\n    console.log('All users:', users);\n\n    // Custom query with parameters\n    const result = await database.customQuery('SELECT * FROM users WHERE name = $1', ['Alice']);\n    console.log('Custom query result:', result);\n\n    // Update a record\n    await database.update('users', { name: 'Alice' }, { name: 'Alice Updated' });\n\n    // Paginate\n    const paginated = await database.paginate('users', { sortby: 'ASC', limit: 10, page: 1 });\n    console.log('Paginated users:', paginated);\n  } finally {\n    await database.release();\n  }\n}\n\nrun().catch(console.error);","lang":"javascript","description":"Demonstrates initialization, CRUD operations, custom query, pagination, and manual client release with PostgresORM."},"warnings":[{"fix":"Always call await db.release() after finishing operations, especially when using a manually acquired client from pool.connect().","message":"Database context (db object) must be released after use to return the connection to the pool.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Call initializeDatabase(config) at application startup.","message":"initializeDatabase must be called exactly once before any db or pool usage, otherwise connections may fail.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Update imports to use named exports: const { initializeDatabase, pool, db } = require('postgresorm');","message":"In version 2.0.0, the API changed from default export to named exports. Old code using 'const pg = require('postgresorm')' and 'pg.initializeDatabase()' may still work, but direct use of 'pool' and 'db' requires destructuring.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Use 'list' with conditions or customQuery instead.","message":"The 'findone' and 'findonerandom' methods are poorly documented and may be removed in future versions.","severity":"deprecated","affected_versions":">=0.0.0"},{"fix":"Always use parameterized customQuery instead of constructing conditions strings.","message":"The 'conditions' parameter in list, paginate, findone, etc. is not parameterized and may be prone to SQL injection if constructed with user input.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'5.1.1':10 'activ':44,48 'advanc':68 'altern':56 'basic':13 'connect':31 'context':39 'crud':14 'custom':19 'databas':38,81 'definit':73 'design':25 'differenti':51 'featur':60,69 'full':59 'full-featur':58 'javascript':77 'lack':67 'librari':41 'lightweight':55 'like':62,70 'low':43 'maintain':49 'manual':35 'migrat':71 'minimalist':5 'model':72 'offer':53 'oper':15 'orm':6,61,78 'pagin':16 'parameter':23 'pool':32 'postgr':80 'postgresorm':1,2 'postgresql':8,79 'provid':12 'queri':20,24 'releas':36 'requir':34 'sequel':63 'simplic':27 'support':21,76 'transact':17 'typeorm':65 'typescript':75 'use':29 'version':9","created_at":"2026-06-05T17:01:00.314415+00:00","updated_at":"2026-06-05T17:01:00.314415+00:00","problems":[{"fix":"Use const { initializeDatabase } = require('postgresorm');","cause":"Using default import instead of named import for initializeDatabase.","error":"TypeError: initializeDatabase is not a function"},{"fix":"Ensure you call db() or db(client) before using CRUD methods.","cause":"Calling db methods without acquiring a client or calling db() first.","error":"Error: Cannot read properties of undefined (reading 'query')"},{"fix":"Call initializeDatabase(config) at the start of your application.","cause":"Accessing pool before initializeDatabase() is called.","error":"Error: pool is not defined"},{"fix":"Check if the context is already released or use a try/finally block to release only once.","cause":"Calling release() on a database context that has already been released.","error":"Error: Client has already been released"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/littlezigy/postgresorm#README.md","github":"https://github.com/littlezigy/postgresorm","docs":null,"changelog":null,"pypi":null,"npm":"postgresorm","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}