npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sql-assassin

v0.2.0

Published

Unfancy SQL builder for ES6

Downloads

9

Readme

sql-assassin — An unfancy node.js SQL builder for ES6

Build Status

Introduction

sql-assassin is an unfancy SQL statement builder for node.js and ES6 template strings. It does not attempt to be an ORM or even understand SQL in any way. It only helps you construct SQL strings with bound parameters.

(Examples need to go here; see test/basic.js for usage information.)

API Reference

This API reference assumes you've imported sql-assassin into the sqlA variable:

import sqlA from 'sql-assassin';
// or
let sqlA = require('sql-assassin');

Template string tag

sqlA`...`: SqlA

The sqlA template string tag is the main interface for constructing SQL statements in sql-assassin. Interpolated values will be treated as follows:

  • A SqlA value will be inserted in-line at that point, including its values.

  • A function will be replaced with a placeholder. The value passed to the placeholder will be the result of calling the function with the args passed to the .value(...args) method.

  • Any other value be replaced with a placeholder and sent as-is.

A value can be checked to see if it is a SqlA by val instanceof sqlA.types.SqlA.

SqlA class methods

this.query(): String

Computes and returns the SQL query for the SqlA instance this, with placeholders for bound values.

this.values(...args): Array<T>

Computes and returns the bound values for the SqlA instance this. Any function values will be called with args and the result will be used as the value.

this.flatten(): SqlA

Returns a new SqlA that is the flattened representation of this. All adjacent strings will be combined together. The new SqlA is functionally identical to the old, but may perform better when rendered many times.

this.concat(sqla: SqlA): SqlA

Returns a new SqlA that is the concatenation of this with sqla with a space in between.

this.parenthesize(): SqlA

Returns a new SqlA that is this wrapped in parentheses.

this.not(): SqlA

Returns a new SqlA that is this prefixed with 'NOT '.

Static methods

sqlA.format(fmt: String, ...args): SqlA

Creates a new SqlA by evaluating the format string fmt with the arguments args. Possible format directives are:

  • %v: Consumes an argument and treats it as a value to be inserted as if it were an interpolated value in a sqlA tagged template string.

  • %%: Inserts the literal % character. Does not consume a value.

sqlA.unsafe(string: String): SqlA

Creates a new SqlA that contains the literal, unescaped string string. Be careful to avoid SQL injection attacks when using this.

sqlA.ident(ident: String): SqlA

Creates a new SqlA that contains the escaped representation of the identifier contained in ident.

sqlA.literal(obj: String): SqlA

Creates a new SqlA that contains the escaped representation of the literal contained in obj. Currently only strings and null work.

sqlA.join(parts: Array, sep: String = ' '): SqlA

Creates a new SqlA that consists of all of parts joined together by sep.

sqlA.and(parts: Array): SqlA

A convenience method for joining by ' AND '.

sqlA.or(parts: Array): SqlA

A convenience method for joining by ' OR '.

sqlA.comma(parts: Array): SqlA

A convenience method for joining by ', '.