sql-str
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

sql-str Build Status

A tiny (667B) utility for building SQL statement strings~!

This module exposes three module definitions:

  • ES Module: dist/sql-str.mjs
  • CommonJS: dist/sql-str.js
  • UMD: dist/sql-str.min.js

Install

$ npm install --save sql-str

Usage

import { toQuery } from 'sql-str';
 
let toAdd = { username: 'lukeed', age: 100 };
let insert = toQuery('users', 'insert', { values:toAdd, returning:true });
//=> insert.text: "insert into users(username,age) values($1,$2) returning *"
//=> insert.values: ['lukeed', 100]
 
let where = { age:'≥18', username:'≠foobar' };
let select = toQuery('users', 'select', { where, limit:25, offset:50 });
//=> select.text: "select * from users where age >= $1 and username != $2 limit 25 offset 50"
//=> select.values: ['18', 'foobar']
 
// TODO

API

toQuery(table, action, opts)

Returns: Object

toOperator(value)

Returns: Array

Splits the value into a [operator, value] tuple. If the value does not start with an operator, then = is assumed.

License

MIT © Luke Edwards

Dependents (0)

Package Sidebar

Install

npm i sql-str

Weekly Downloads

9

Version

0.2.0

License

MIT

Unpacked Size

11.6 kB

Total Files

7

Last publish

Collaborators

  • lukeed