o2sql is a lightweight JavaScript library for programmatically generating PostgreSQL queries with parameterized values. It provides a fluent API to build SELECT, INSERT, UPDATE, and DELETE statements, abstracting the SQL generation into an AST (Abstract Syntax Tree) that can be converted to `{ sql, values }` objects compatible with node-postgres (`pg`). Version 4.0.20 has no known breaking changes from earlier v4 releases. Key differentiators: simple, minimal API; automatic identifier quoting; direct integration with the `pg` library via `.toParams()`. It does not support MySQL despite the keyword.
npm install o2sqlNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Generate a parameterized SELECT query with filtering, ordering, and limit.
This is by design; the generated SQL is valid and works with PostgreSQL despite the extra quotes.
Use `o2sql.e()` or `o2sql.i()` to build complex conditions.
Manually quote the function name using `o2sql.i()` if needed.
Validate or whitelist operators before passing to `.op()`.
Run `npm install o2sql` and use `const o2sql = new (require('o2sql'))();` (CommonJS) or `import O2Sql from 'o2sql'; const o2sql = new O2Sql();` (ESM).Create an instance first: `const o2sql = new (require('o2sql'))();` then `o2sql.select(...)`.Ensure you call `select` and `from` before `where`. Example: `o2sql.select(['id']).from('users').where({id: 1}).toParams()`.