Registry / database / tinypg-parser

tinypg-parser

JSON →
library1.0.6jsnpmunverified

A lightweight utility for parsing parameterized SQL templates, designed for use with TinyPg. This package is a companion to TinyPg that handles the interpolation of query parameters into SQL strings. Currently at version 1.0.6, with Node.js >= 8.0.0 support. Ships TypeScript definitions. It is minimal and focused solely on SQL parsing without any database connectivity or connection pooling. Differentiators: zero dependencies, synchronous parsing, and tight integration with TinyPg's parameter syntax. The release cadence is low as the library is stable and mature.

npm install tinypg-parser
INSTALL
IMPORT
SIG · TINYPG-PARSER
T
tinypg-parser
databasejavascriptv1.0.6
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.

Parser
import { Parser } from 'tinypg-parser'
const Parser = require('tinypg-parser').Parser
ESM or CJS: import { Parser } is the correct named import. Using require with .Parser is incorrect because the module exports the constructor directly.

Parses a parameterized SQL string with named parameters into a parameterized query string and values array suitable for PostgreSQL.

import { Parser } from 'tinypg-parser'; const parser = new Parser(); const query = 'SELECT * FROM users WHERE id = :id AND name = :name'; const params = { id: 1, name: 'Alice' }; const { text, values } = parser.parse(query, params); console.log(text); // 'SELECT * FROM users WHERE id = $1 AND name = $2' console.log(values); // [1, 'Alice'] // Using named parameters in the SQL const sql = 'INSERT INTO items (title, price) VALUES (:title, :price)'; const insertParams = { title: 'Widget', price: 9.99 }; const result = parser.parse(sql, insertParams); console.log(result.text); // 'INSERT INTO items (title, price) VALUES ($1, $2)' console.log(result.values); // ['Widget', 9.99]
Debug
Known issues
gotchaParameter names must follow the pattern :identifier and cannot contain special characters.
fix
Use alphanumeric characters and underscores for parameter names.
affects: all
gotchaThe parser does not support nested or complex parameter expressions; only simple named parameters.
fix
Manually handle any transformations before passing to parser.
affects: all
Errors
Common errors & fixes
Error: parameter must be an object
Passing a non-object (e.g., string or number) as the params argument.
fix
Ensure params is an object with key-value pairs matching the named parameters in the SQL.
ReferenceError: Parser is not defined
Using an incorrect import or missing import statement.
fix
Use 'import { Parser } from "tinypg-parser"' (ESM) or 'const { Parser } = require("tinypg-parser")' (CJS).
Upgrade
Version history
1.0.6latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
18 hits · last 30 days
node
14
Meta
2
Bingbot
1
OpenAI (training)
1
Resources
tinypg-parser — npm install tinypg-parser · libregistry