Registry / database / sqliterally

sqliterally

JSON →
library1.0.3jsnpmunverified

Lightweight SQL query builder using tagged template literals for composing safe, parameterized queries. Current stable version is 1.0.3, released intermittently as a mature, stable library. It produces queries compatible with node-pg and mysql, supports nested subqueries, and has no external dependencies. Unlike extensive query builders like Knex.js, SQLiterally focuses on composability and safety without abstracting away SQL, giving developers full control.

npm install sqliterally
INSTALL
IMPORT
SIG · SQLITERALLY
S
sqliterally
databasejavascriptv1.0.3
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.

sql
import { sql } from 'sqliterally'
const { sql } = require('sqliterally')
ESM import is preferred; CommonJS works but may require esModuleInterop in TypeScript.
query
import { query } from 'sqliterally'
import query from 'sqliterally'
query is a named export, not default.
sqliterally
import * as sqliterally from 'sqliterally'
For namespace import; both sql and query are available as properties.
SQLiterally
import SQLiterally from 'sqliterally'
No default export exists; attempting this will return undefined.

Demonstrates basic usage of sql and query functions to build parameterized SQL queries with tagged templates.

import { sql, query } from 'sqliterally'; let movie = 'Memento', year = 2001; // Using sql tagged template let result = sql`SELECT director FROM movies WHERE title = ${movie}`; console.log(result); // => { text: 'SELECT director FROM movies WHERE title = $1', sql: 'SELECT director FROM movies WHERE title = ?', values: ['Memento'] } // Using query builder let q = query .select`director` .select`year` .from`movies` .where`title = ${movie}` .limit`5`; if (year) q = q.where`year >= ${year}`; let built = q.build(); console.log(built); // => { text: `SELECT director, year FROM movies WHERE title = $1 AND year >= $2 LIMIT 5', sql: 'SELECT director, year FROM movies WHERE title = ? AND year >= ? LIMIT 5', values: ['Memento', 2001] }
Debug
Known issues
gotchaThe sql function only interpolates values safely; never use ${...} with raw strings as it may lead to SQL injection if user input is embedded without parameterization.
fix
Always pass user input as template substitution values, not as part of the SQL string literal.
affects: >=1.0.0
gotchaThe query builder methods (select, from, where, etc.) mutate the query object and return it for chaining. Reusing a query object after building may lead to unexpected results due to internal state.
fix
Clone the query before building if you need to reuse it, or use sql`...` for one-off queries.
affects: >=1.0.0
gotchaThe query builder does not enforce SQL syntax; it only arranges clauses. Writing invalid SQL will produce invalid queries.
fix
Validate your SQL manually or use sql tagged literal for more control.
affects: >=1.0.0
deprecatedCommonJS require('sqliterally') may be deprecated in future versions as the package encourages ESM.
fix
Use import syntax (ESM) for forward compatibility.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'sqliterally'
Package not installed or incorrect import path.
fix
Run 'npm install sqliterally' and ensure import is from 'sqliterally' (not 'sqliterally/dist/sqliterally').
TypeError: (0 , _sqliterally.sql) is not a function
Default import used instead of named import; sql is not a default export.
fix
Correct import: import { sql } from 'sqliterally'
query is not a function
Importing sqliterally incorrectly, e.g., import * as sqliterally from 'sqliterally' and then calling sqliterally.query() instead of using the named export.
fix
Use import { query } from 'sqliterally'
Property 'build' does not exist on type '...'
Typing issue if using TypeScript with an older version of types.
fix
Update to latest version and check that you are using the query builder object, not the sql function.
Upgrade
Version history
1.0.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
14 hits · last 30 days
node
10
Meta
1
OpenAI (training)
1
Resources
sqliterally — npm install sqliterally · libregistry