Selectstar is a JavaScript/TypeScript library for generating safe, parameterized SQL queries for PostgreSQL using tagged template literals. Current stable version is 1.1.11, maintained since 2018. It provides primitives for constructing dynamic queries without SQL injection risks: parameterized values, query fragments (template), dynamic identifiers, and lists. Unlike alternatives like squel or knex, selectstar stays close to raw SQL syntax while enforcing parameterization — it is ignorant of query semantics, making it ideal for complex or raw SQL generation. It is fully typed (TypeScript declarations included) and integrates directly with node-postgres (pg) via query objects containing text and values. The package has no runtime dependencies.
npm install selectstarNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates basic parameterized query, dynamic identifier, and integration with node-postgres pool.query.
Cache static queries outside hot loops if needed; e.g., const query = sql`SELECT 1`;
Validate or whitelist identifiers (e.g., column names) before passing to identifier().
Check array length before constructing list: if (items.length === 0) throw new Error('Need at least one item');Wrap template usage in ${} within sql``: sql`SELECT * FROM ${template`users`}` — though in this simple case identifier is safer.Upgrade to >=1.0.0 and use { text, values } object. Old call sites: { sql: '...', params: [...] } should be changed.Change import to: import { sql } from 'selectstar';Run 'npm install selectstar' and ensure tsconfig.json includes 'node_modules/@types' or 'moduleResolution': 'node'.
Add: import { identifier } from 'selectstar';Use query.text to get the SQL string, or JSON.stringify(query) to inspect both text and values.
No dependency data recorded yet.