Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including mysql-named-params-escape with all npm packages installed. Try it out:

var mysqlNamedParamsEscape = require("mysql-named-params-escape")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

mysql-named-params-escape v1.0.2

Custom query format for named parameters in node-mysql.

MYSQL Named Params Escape

Install

npm install mysql-named-params-escape

Usage

var npEscape = require('mysql-named-params-escape');

Writing queries

var query = "SELECT ::something FROM ::table WHERE ::table.::whatever = :value";
var params = {
  something: 'title',
  table: 'foo',
  whatever: 'id',
  value: 123
};

// SELECT `title` FROM `foo` WHERE `foo`.`id` = 123;

Manual escaping

query = npEscape(query, params);

connection.query(query);

Setting queryFormat

connection.config.queryFormat = npEscape;

connection.query(query, params);

Parameters

query

Type: String

The string of MYSQL code to be escaped.
:: followed by a word denotes an identifier to be escaped.
: followed by a word denotes a value to be escaped.

params

Type: Object

An object in which the keys correspond to placeholders in the query. The placeholders will be replaced with the values from the object.

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free