{"id":28041,"library":"pg-query-string","title":"pg-query-string","description":"pg-query-string is a small library (v0.1.7, stable) for building PostgreSQL query strings with parameterized values. It is a fork of squel, hardcoded to PostgreSQL, with type coercion and ES6 class-based schema/table constructs. Current version is 0.1.7, no recent updates. Key differentiator: produces both SQL text and parameter arrays for safe execution.","status":"maintenance","version":"0.1.7","language":"javascript","source_language":"en","source_url":"https://github.com/pyramation/sql-query","tags":["javascript","postgres","query"],"install":[{"cmd":"npm install pg-query-string","lang":"bash","label":"npm"},{"cmd":"yarn add pg-query-string","lang":"bash","label":"yarn"},{"cmd":"pnpm add pg-query-string","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Package is ESM-only. Default export is not available.","wrong":"const { Table } = require('pg-query-string')","symbol":"Table","correct":"import { Table } from 'pg-query-string'"},{"note":"Default import does not exist; use named imports.","wrong":"import pgqs from 'pg-query-string'","symbol":"Schema","correct":"import { Schema } from 'pg-query-string'"},{"note":"For dynamic imports, use ESM dynamic import syntax in Node >= 13.2 or with type: module.","wrong":"const Table = require('pg-query-string').Table","symbol":"Table","correct":"const { Table } = await import('pg-query-string')"}],"quickstart":{"code":"import { Schema, Table } from 'pg-query-string';\n\nconst schema = new Schema('my_schema');\nconst table = schema.table('users', {\n  id: 'uuid',\n  username: 'text',\n  active: 'boolean'\n});\n\nconst result = table.update(\n  { active: true },\n  { id: 1 }\n);\n\nconsole.log(result.text);\n// UPDATE \"my_schema\".users SET active = $1::boolean WHERE (id = $2::uuid)\nconsole.log(result.values);\n// [ true, 1 ]","lang":"typescript","description":"Creates a schema and table with typed columns, then builds an UPDATE query with parameterized values."},"warnings":[{"fix":"Use import syntax or configure bundler to handle ESM.","message":"Package is ESM-only; requires Node >= 13 or a bundler like webpack/esbuild.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Consider using 'pg' or 'knex' for more maintained query building.","message":"The package has not been updated since 2019 and may have unpatched security issues.","severity":"deprecated","affected_versions":">=0.1.0"},{"fix":"Use Map or arrays to guarantee order.","message":"Object literals for insert/update produce $1, $2, etc. in the order of object keys, which is non-deterministic in older JavaScript engines.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Use snake_case for schema/table names to avoid quoting issues.","message":"Schema and table names are quoted with double quotes, which are case-sensitive in PostgreSQL. Ensure lowercase names.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-05-09T00:00:00.000Z","next_check":"2026-08-07T00:00:00.000Z","problems":[{"fix":"Change to: import { Table } from 'pg-query-string'","cause":"Using default import instead of named import.","error":"TypeError: (0 , _pgQueryString.Table) is not a constructor"},{"fix":"Add 'type': 'module' to package.json or use dynamic import().","cause":"Using ESM import in a CommonJS file without 'type': 'module'.","error":"SyntaxError: Cannot use import statement outside a module"},{"fix":"Correct import: import { Schema } from 'pg-query-string'","cause":"Using const without assigning import result.","error":"Missing initializer in const declaration"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}