# sql-helpers

> A tiny wrapper around knex and other utility functions to give it a simple interface.

Latest version **1.0.2** (published 2015-11-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install sql-helpers
pnpm add sql-helpers
yarn add sql-helpers
bun add sql-helpers
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2015-11-10 |
| First published | 2015-11-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Gregori Kanatzidis |
| Maintainers | kanatzidis |
| Keywords | knex, sql, utility |

## Links

- npm: https://www.npmjs.com/package/sql-helpers
- Repository: https://github.com/kanatzidis/sql-helpers
- Homepage: https://github.com/kanatzidis/sql-helpers#readme
- Issues: https://github.com/kanatzidis/sql-helpers/issues
- npm.io page: https://npm.io/package/sql-helpers

## Alternatives

- [lodash.assign](https://npm.io/package/lodash.assign.md) — 2.3M weekly downloads
- [lodash.chunk](https://npm.io/package/lodash.chunk.md) — 1.8M weekly downloads
- [react-native-ios-utilities](https://npm.io/package/react-native-ios-utilities.md) — 138.5K weekly downloads
- [@technically/lodash](https://npm.io/package/@technically/lodash.md) — 50.9K weekly downloads
- [@fluid-topics/ft-icon](https://npm.io/package/@fluid-topics/ft-icon.md) — 20.6K weekly downloads

## Recent versions

- 1.0.2 (latest) — 2015-11-10
- 1.0.1 — 2015-11-05
- 1.0.0 — 2015-11-05

## README

## sql-helpers

A tiny wrapper around knex and other utility functions to give it a simple interface.

### Installation

`npm install sql-helpers`

### Usage

```
var sh = require('sql-helpers');

var knex = require('knex')({
  client: 'pg',
  connection: {
    host     : '127.0.0.1',
    user     : 'postgres',
    password : 'password',
    database : 'dbname'
  }
});

knex = sh.wrap(knex);

var buildValues = sh.buildValues;

var sql = 'INSERT INTO users (username, password_hash, email, favorite_color) VALUES ('
          + buildValues([
            'yourUsername',
            '4Cc1h1Nq02YthshONRAB5IFZlwdrMGXZumE543tERRihu',
            'yourUsername@example.com',
            'blue'
            ] + ') returning id');

knex.run(sql, function(err, user) {
  // Do something
}, true);
```

#### API

`knex.run`:

Takes three arguments - a sql query, a callback, and optionally a boolean if you expect the query to return only one result. The callback also takes two arguments - an error and the result, which will either be an object (if you pass `true` as the third argument to `knex.run`), or an array.

```
knex.run('SELECT * FROM users', function(err, users) {
  _.each(users, function(user) {
    // Do something
  });
});
```

`buildValues`:

Takes an array of strings, puts quotes around each of them, then concatenates them with comma separators. Used for writing sql queries. Designed for use with postgres, may not work for other engines.

```
buildValues(['your', 12]);
// "\'your\', \'12\'"
```

### License

MIT

---
_Source: https://npm.io/package/sql-helpers · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
