{"id":43984,"library":"sqliterally","title":"SQLiterally","description":"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.","status":"active","version":"1.0.3","language":"javascript","source_language":"en","source_url":"https://github.com/terkelg/sqliterally","tags":["javascript","db","sql","orm","mysql","query","builder","strings","postgres"],"install":[{"cmd":"npm install sqliterally","lang":"bash","label":"npm"},{"cmd":"yarn add sqliterally","lang":"bash","label":"yarn"},{"cmd":"pnpm add sqliterally","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM import is preferred; CommonJS works but may require esModuleInterop in TypeScript.","wrong":"const { sql } = require('sqliterally')","symbol":"sql","correct":"import { sql } from 'sqliterally'"},{"note":"query is a named export, not default.","wrong":"import query from 'sqliterally'","symbol":"query","correct":"import { query } from 'sqliterally'"},{"note":"For namespace import; both sql and query are available as properties.","wrong":"","symbol":"sqliterally","correct":"import * as sqliterally from 'sqliterally'"},{"note":"No default export exists; attempting this will return undefined.","wrong":"import SQLiterally from 'sqliterally'","symbol":"SQLiterally","correct":""}],"quickstart":{"code":"import { sql, query } from 'sqliterally';\n\nlet movie = 'Memento', year = 2001;\n\n// Using sql tagged template\nlet result = sql`SELECT director FROM movies WHERE title = ${movie}`;\nconsole.log(result);\n// => { text: 'SELECT director FROM movies WHERE title = $1', sql: 'SELECT director FROM movies WHERE title = ?', values: ['Memento'] }\n\n// Using query builder\nlet q = query\n    .select`director`\n    .select`year`\n    .from`movies`\n    .where`title = ${movie}`\n    .limit`5`;\n\nif (year) q = q.where`year >= ${year}`;\n\nlet built = q.build();\nconsole.log(built);\n// => { 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] }","lang":"javascript","description":"Demonstrates basic usage of sql and query functions to build parameterized SQL queries with tagged templates."},"warnings":[{"fix":"Always pass user input as template substitution values, not as part of the SQL string literal.","message":"The 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Clone the query before building if you need to reuse it, or use sql`...` for one-off queries.","message":"The 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Validate your SQL manually or use sql tagged literal for more control.","message":"The query builder does not enforce SQL syntax; it only arranges clauses. Writing invalid SQL will produce invalid queries.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use import syntax (ESM) for forward compatibility.","message":"CommonJS require('sqliterally') may be deprecated in future versions as the package encourages ESM.","severity":"deprecated","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.0.3':19 'abstract':58 'away':59 'builder':5,48,71 'compat':30 'compos':11,54 'control':64 'current':15 'db':66 'depend':44 'develop':62 'extens':46 'extern':43 'focus':52 'full':63 'give':61 'intermitt':21 'javascript':65 'knex.js':50 'librari':26 'lightweight':2 'like':49 'liter':9 'matur':24 'mysql':36,69 'nest':38 'node':33 'node-pg':32 'orm':68 'parameter':13 'pg':34 'postgr':73 'produc':28 'queri':4,14,29,47,70 'releas':20 'safe':12 'safeti':56 'sql':3,60,67 'sqliter':1,51 'stabl':16,25 'string':72 'subqueri':39 'support':37 'tag':7 'templat':8 'unlik':45 'use':6 'version':17 'without':57","created_at":"2026-06-05T17:02:25.083345+00:00","updated_at":"2026-06-05T17:02:25.083345+00:00","problems":[{"fix":"Run 'npm install sqliterally' and ensure import is from 'sqliterally' (not 'sqliterally/dist/sqliterally').","cause":"Package not installed or incorrect import path.","error":"Cannot find module 'sqliterally'"},{"fix":"Correct import: import { sql } from 'sqliterally'","cause":"Default import used instead of named import; sql is not a default export.","error":"TypeError: (0 , _sqliterally.sql) is not a function"},{"fix":"Use import { query } from 'sqliterally'","cause":"Importing sqliterally incorrectly, e.g., import * as sqliterally from 'sqliterally' and then calling sqliterally.query() instead of using the named export.","error":"query is not a function"},{"fix":"Update to latest version and check that you are using the query builder object, not the sql function.","cause":"Typing issue if using TypeScript with an older version of types.","error":"Property 'build' does not exist on type '...'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/terkelg/sqliterally#readme","github":"https://github.com/terkelg/sqliterally","docs":null,"changelog":null,"pypi":null,"npm":"sqliterally","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}