sql-format-utils
v1.2.0
Published
A Node.js module to manipulate strings and dates for use with SQL database interactions.
Downloads
21
Readme
sql-format-utils
Utility functions that manipulate strings and dates for use with SQL database interactions.
Install
// Saves to package.json
npm install --save sql-format-utils
Instantiate
var dbUtils = require('sql-format-utils');
Examples
Return a list with each array or list element in single quotes; for SQL IN statements.
var arr = [1, 2, 3, 4]; console.log(dbUtils.toSQLList(arr)); // "'1', '2', '3', '4'"
var list = '1,2,3,4'; console.log(dbUtils.listToSQLList(list)); // "'1', '2', '3', '4'"
Return a string representation of a given date, formatted for SQL insertion ('yyyy-mm-dd HH:MM:ss').
console.log(dbUtils.formatDateForSQL(new Date())); // '2020-01-02 03:04:05'
Return a string with all single quotes JavaScript-escaped.
console.log(dbUtils.escapeSingleQuotes("She's got her mother's eyes.")); // "She\'s got her mother\'s eyes."
console.log(dbUtils.escapeSingleQuotes("She's got her mother's eyes.", "'")); // "She''s got her mother''s eyes."