Registry / database / sqlstring-sqlite

sqlstring-sqlite

JSON →
library0.1.1jsnpmunverified

A SQLite-adapted fork of mysqljs/sqlstring that provides simple SQL string escaping and formatting for SQLite. Version 0.1.1 is the latest release, with no defined release cadence. It modifies the escape character maps for SQLite compatibility but does not update unit tests, so tests will not pass. Differentiates from the original by supporting SQLite-specific escaping rules.

npm install sqlstring-sqlite
INSTALL
IMPORT
SIG · SQLSTRING-SQLITE
S
sqlstring-sqlite
databasejavascriptv0.1.1
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.

SqlString
const SqlString = require('sqlstring-sqlite');
import SqlString from 'sqlstring-sqlite';
The package does not ship TypeScript definitions; use CommonJS require. ESM import may not work.
escape
const escaped = require('sqlstring-sqlite').escape(value);
const { escape } = require('sqlstring-sqlite');
destructuring works as escape is an exported property, but correct import is fine.
format
const sql = require('sqlstring-sqlite').format('SELECT ?', [value]);
const { format } = require('sqlstring-sqlite');
destructuring works but CommonJS require is more idiomatic for Node < 14.

Shows basic usage of escape and format methods for SQLite queries.

const SqlString = require('sqlstring-sqlite'); const userId = 'some user input'; const sql = SqlString.format('SELECT * FROM users WHERE id = ?', [userId]); console.log(sql); // SELECT * FROM users WHERE id = 'some user input' const post = { id: 1, title: 'Hello SQLite' }; const insertSql = SqlString.format('INSERT INTO posts SET ?', post); console.log(insertSql); // INSERT INTO posts SET `id` = 1, `title` = 'Hello SQLite'
Debug
Known issues
breakingUnit tests from original mysqljs/sqlstring have not been updated, so npm test will fail.
fix
Do not rely on tests; verify behavior manually or write your own tests.
affects: >=0.0.0
gotchaThe package uses backtick quoting for identifiers instead of SQLite's double quotes (e.g., `id` instead of "id").
fix
SQLite accepts backticks for compatibility but double quotes are standard. Manually adjust if needed.
affects: >=0.0.0
gotchaValues of type Date are converted to 'YYYY-mm-dd HH:ii:ss' string format, but SQLite expects ISO 8601 format (YYYY-mm-ddTHH:ii:ss).
fix
Use a custom toSqlString method to convert dates to SQLite format.
affects: >=0.0.0
gotchaObject property values that are functions are skipped; nested objects use toString() which may not produce SQL-safe strings.
fix
Ensure all object values are primitives or implement toSqlString.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'sqlstring-sqlite'
Package not installed
fix
Run 'npm install sqlstring-sqlite'
SqlString.escape is not a function
Using import statement with CommonJS module
fix
Change to const SqlString = require('sqlstring-sqlite'); or use dynamic import.
Tests failing: expected '...' but got '...'
Test suite not updated for SQLite
fix
Ignore failing tests or update them to expect SQLite escaping.
Upgrade
Version history
0.1.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
19 hits · last 30 days
node
16
Meta
2
OpenAI (training)
1
Resources