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

sqlcmd

v3.0.4

Published

SQL command builder. String-based and incremental, with mutable and immutable interfaces.

Downloads

269

Readme

sqlcmd

latest version published to npm Travis CI build status Coverage status on Coveralls

Coarse-grained partially composable SQL.

npm install --save sqlcmd

Basic queries

import {Connection} from 'sqlcmd'
const db = new Connection()

Select(), Insert(), Update(), and Delete() are all functions of db that take a single argument, the name of the table they are operating on, and return a different type of query object.

The examples below assume a connection is available somewhere, which is not shown. See sqlcmd-pg for a complete example.

I've elided error handling below, for concision, but in practice that's a recipe for disaster, or at least a really awful debugging experience.

var user_name = 'Chris'

db.Select('friendships')
.where('source = ? OR target = ?', user_name, user_name)
.execute((err, friendships) => {
  console.log("All of Chris's connections: %j", friendships)
})

db.Insert('friendships')
.set({source: 'Chris', target: 'Jess'})
.returning('*')
.execute((err, rows) => {
  // we've asked for "RETURNING *", so we get back a list of one row.
  console.log('inserted row: %j', rows[0])
})

TODO: more documentation. (When is that not a TODO?)

Ideas

Every SQL command is an instance of a general SQL Command class, and can be modified (mutated) or built upon to create new instances. SQL syntax is regular, but we want to be able to build commands (especially queries) incrementally.

Most SQL databases loosely adhere to a standard, but every implementation has extensions or flexibility for better compatibility. This library does not make provisions for different implementations. Instead, it is string-based, so if you use it to create a table, you need to know what types and constraints your database implementation supports.

Commands

SQL parameterization embeds references to external objects in plain strings. Strings are just arrays of characters, so a parameterized string is just an array of strings interspersed with parameter objects. We could model those sequences as an array of stuff like "SqlString" and "SqlParameter" instances, but since pg and sqlite3 both distinguish between the query string and a parameters object/array when performing queries, we'll use a similar model. When

sqlcmd comes with several built-in commands. These classes have both mutable and immutable interfaces. The mutable interface uses method names prefixed by _. These methods modify the command instance's statement and/or parameters and return this, so that they're chainable. The non-prefixed methods clone the command instance first, and then perform the mutable command on the newly created copy, returning the copy and leaving the original command untouched. Every command must also implement the Command#toSQL(), which takes no arguments and returns a single string. It does not modify the command.

License

Copyright 2014-2015 Christopher Brown. MIT Licensed.