Registry / database / o2sql-pg

o2sql-pg

JSON →
library1.0.11jsnpmunverified

o2sql-pg is a ready-to-use tool to have o2sql (a SQL query builder) working with pg (node-postgres). It provides an O2sqlPg factory that creates an o2sql instance configured with a PostgreSQL connection pool. It supports building and executing SELECT/INSERT/UPDATE/DELETE queries using the o2sql fluent API, with support for nested group columns, transactions, and direct pg queries. Current stable version is 1.0.11. It wraps the o2sql and pg libraries, offering a convenient integration layer. Key differentiator: combines o2sql's query builder with pg's connection management, handling pool creation internally for simplicity.

npm install o2sql-pg
INSTALL
IMPORT
SIG · O2SQL-PG
O
o2sql-pg
databasejavascriptv1.0.11
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.

default
import o2sqlPg from 'o2sql-pg'
const o2sqlPg = require('o2sql-pg')
Package ships as ESM with a default export. In CommonJS, use require('o2sql-pg').default or use dynamic import.
O2sqlPg
import O2sqlPg from 'o2sql-pg'
import { O2sqlPg } from 'o2sql-pg'
The default export is the O2sqlPg factory function, it is not a named export.
Client
import { Client } from 'pg'
No direct export from o2sql-pg
Client is imported from 'pg', not from o2sql-pg.

Creates an o2sql instance with pg pool config, runs a simple select query, and prints results.

import o2sqlPg from 'o2sql-pg'; const o2sql = o2sqlPg({ user: process.env.PGUSER ?? 'postgres', host: process.env.PGHOST ?? 'localhost', database: process.env.PGDATABASE ?? 'test', password: process.env.PGPASSWORD ?? '', port: parseInt(process.env.PGPORT ?? '5432'), }); const list = await o2sql.select(['id', 'name']).from('users').execute(); console.log(list);
Debug
Known issues
gotchaThe factory function (default export) returns an o2sql instance directly, not a class. You cannot instantiate it with 'new'.
fix
Simply call o2sqlPg(config) without new.
affects: >=1.0.0
gotchaWhen using transactions, the client must be passed as the last argument to .execute() methods inside the transaction callback.
fix
Always pass the client: await o2sql.select(...).execute(client);
affects: >=1.0.0
deprecatedDirect use of o2sql.query() is not recommended; prefer the built-in execute method.
fix
Use o2sql.select(...).execute() instead of o2sql.query().
affects: >=1.0.0
gotchaThe package does not support TypeScript types out of the box. You may need to install @types/pg and o2sql types separately.
fix
Install @types/pg and check for community type definitions for o2sql.
affects: >=1.0.0
Errors
Common errors & fixes
o2sqlPg is not a function
Using named import instead of default import in ESM
fix
Use: import o2sqlPg from 'o2sql-pg'; (no curly braces)
Cannot read property 'select' of undefined
Calling o2sqlPg incorrectly without passing config or forgetting to assign the result
fix
const o2sql = o2sqlPg({...}); then use o2sql.select(...)
Client must be connected
Passing a client that has not been connected yet, or reusing a closed client
fix
In transactions, the client is provided by the library; do not manually connect/disconnect inside the callback.
Upgrade
Version history
1.0.11latest on npm
Audit
Dependencies
o2sqlrequiredCore query builder library
pgrequiredPostgreSQL client for Node.js
Agent activity
9 hits · last 30 days
node
8
Resources
o2sql-pg — npm install o2sql-pg · libregistry