1.2.0 • Published 10 years ago

sql-format-utils v1.2.0

Weekly downloads
2
License
Apache-2.0
Repository
github
Last release
10 years ago

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

  1. 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'"
  2. 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'
  3. 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."
1.2.0

10 years ago

1.1.2

10 years ago

1.1.1

10 years ago

1.1.0

10 years ago

1.0.9

10 years ago

1.0.7

10 years ago

1.0.6

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago