JSPM

sql-tag

0.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2598
  • Score
    100M100P100Q110387F
  • License MIT

A template tag for writing elegant sql strings

Package Exports

  • sql-tag

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (sql-tag) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

sql-tag

A template tag for writing elegant sql strings based on ES6 tagged template strings.

Status

npm version build status

Installation

Install the package via npm:

$ npm install sql-tag

Usage

Arguments

  1. query (string): The sql query.
  2. [...*] (...*): The query replacements.

Returns

(Object): A structured object with the sql query string and its replacements.

Example

var sql = require('sql-tag');

var out = sql`SELECT * FROM "Foo" WHERE id = ${1}`;
// => { query: 'SELECT * FROM "Foo WHERE id = ?', values: [1] }

The tag itself is framework agnostic. It should just require a small modification to the query generator function.

NOTE: the sql tag does not provide any kind of escaping safety. It delegates that work to the underlying framework.

Integrating with sequelize

Check out the sequelize-sql-tag plugin.

Integrating with pg

Check out the pg-sql-tag plugin.

Tests

$ npm test

Credits

Inspired by the awesome Taras Mitran post.

License

MIT