Socket
Book a DemoInstallSign in
Socket

sql-str

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sql-str

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

latest
Source
npmnpm
Version
0.2.0
Version published
Maintainers
1
Created
Source

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

Keywords

pg

FAQs

Package last updated on 23 Oct 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts