Registry / database / friendly-sql

friendly-sql

JSON →
library0.1.5jsnpmunverified

Write SQL conveniently in Node.js projects by separating SQL statements into external .sql files with ID annotations. Current stable version is 0.1.5. This lightweight library avoids string concatenation and array joins by parsing SQL files and supporting variable substitution using braces and positional parameters. It is suitable for small to medium projects that prefer SQL-in-files over ORMs or template literals. No active development observed since 2016.

npm install friendly-sql
INSTALL
IMPORT
SIG · FRIENDLY-SQL
F
friendly-sql
databasejavascriptv0.1.5
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.

parse
const sql = require('friendly-sql').parse('family.sql');
import { parse } from 'friendly-sql';
The package does not support ESM. Use CommonJS require. The parse function returns a function to query by ID.
parse
import { parse } from 'friendly-sql';
If using TypeScript or ESM, you must use the default export or named export 'parse'. However, the package lacks type definitions.
default import
import friendlySql from 'friendly-sql';
Alternatively, import default and call friendlySql.parse().

Shows how to load a SQL file, retrieve a statement by ID, perform variable substitution for braces, and enable logging.

// family.sql -- id: Select users SELECT first_name, last_name FROM users WHERE age > $minAge ORDER BY last_name; // app.js const sql = require('friendly-sql').parse('family.sql'); // Get SQL for 'Select users', no variable substitution console.log(sql('Select users')); // With variable substitution (braces in SQL) console.log(sql('Select users', { field: 'age' })); // Enable logging sql.log = true; console.log(sql('Select users', { field: 'age' }));
Debug
Known issues
deprecatedPackage has not been updated since 2016. Consider using more modern alternatives like @databases/sql or squel.
fix
Migrate to a maintained SQL template library.
affects: >=0.0.0
gotchaVariable substitution only works for brace-enclosed markers (e.g., {field}) not $param unless you manually replace.
fix
Use brace syntax for substitution. SQLite parameters like $name are left as-is.
affects: 0.1.5
gotchaSQL file IDs are case-sensitive and must exactly match the comment annotation after '-- id: '.
fix
Ensure ID in code matches exactly including whitespace.
affects: >=0.0.0
Errors
Common errors & fixes
Error: Cannot find module 'friendly-sql'
Package not installed or not in node_modules.
fix
Run 'npm install friendly-sql' in your project directory.
friendly-sql is not a function
Incorrect import style. parse() returns a function but require returns an object.
fix
Use const sql = require('friendly-sql').parse('file.sql');
ENOENT: no such file or directory, open 'family.sql'
SQL file path is relative to current working directory, not the script's directory.
fix
Use absolute path or path.join(__dirname, 'family.sql').
Upgrade
Version history
0.1.5latest on npm
Audit
Dependencies
fsrequiredNode built-in used to read SQL files
pathrequiredNode built-in used for file path resolution
Agent activity
5 hits · last 30 days
node
4
Resources
friendly-sql — npm install friendly-sql · libregistry