GithubHelp home page GithubHelp logo

dschinkel / pg-escape Goto Github PK

View Code? Open in Web Editor NEW

This project forked from segmentio/pg-escape

0.0 0.0 0.0 283 KB

sprintf-style postgres query escaping and helper functions

Makefile 1.52% JavaScript 98.48%

pg-escape's Introduction

pg-escape

Sprintf-style postgres query formatting and escape helper functions.

Installation

$ npm install pg-escape

Example

var sql = escape('INSERT INTO %I VALUES(%L)', 'books', "O'Reilly");
console.log(sql);

yields:

INSERT INTO books VALUES('O''Reilly')

API

escape(fmt, ...)

Format the given arguments.

escape.string(val)

Format as a simple string.

escape.dollarQuotedString(val)

Format as a dollar quoted string

escape.ident(val)

Format as an identifier.

escape.literal(val)

Format as a literal.

Formats

  • %s formats the argument value as a simple string. A null value is treated as an empty string.
  • %Q formats the argument value as a dollar quoted string. A null value is treated as an empty string.
  • %I treats the argument value as an SQL identifier, double-quoting it if necessary. It is an error for the value to be null.
  • %L quotes the argument value as an SQL literal. A null value is displayed as the string NULL, without quotes.
  • %% In addition to the format specifiers described above, the special sequence %% may be used to output a literal % character.

License

MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.