# rdbql

> Cross compatible SQL query builder for node

Latest version **0.0.5** (published 2013-03-29) · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install rdbql
pnpm add rdbql
yarn add rdbql
bun add rdbql
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.0.5 |
| Published | 2013-03-29 |
| First published | 2013-03-17 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Anthony Hogg |
| Maintainers | ynohat |
| Keywords | sql, syntax, sqlite3, mysql, rdbms, query builder, query |

## Links

- npm: https://www.npmjs.com/package/rdbql
- Repository: http://github.com/ynohat/node-rdbql
- Issues: http://github.com/ynohat/node-rdbql/issues
- npm.io page: https://npm.io/package/rdbql

## Alternatives

- [gamedig](https://npm.io/package/gamedig.md) — 29.3K weekly downloads
- [join-monster](https://npm.io/package/join-monster.md) — 12.8K weekly downloads
- [masked](https://npm.io/package/masked.md) — 5.5K weekly downloads
- [@comunica/actor-query-process-explain-logical](https://npm.io/package/@comunica/actor-query-process-explain-logical.md) — 4.7K weekly downloads
- [@veracity/vui](https://npm.io/package/@veracity/vui.md) — 4.6K weekly downloads

## Recent versions

- 0.0.5 (latest) — 2013-03-29
- 0.0.4 — 2013-03-24
- 0.0.3 — 2013-03-17
- 0.0.2 — 2013-03-17
- 0.0.1 — 2013-03-17

## README

node-rdbql
============

(yet another) SQL syntax helper for node.js

## Install

<pre>
npm install [-g] rdbql
</pre>

## Status

All examples have been tested with sqlite3. They *should* work with MySQL as well, and maybe postgre, but that hasn't been tested yet.

## Why?

Applications using a RDBMS of some kind quickly get messy when building SQL "from scratch".

<pre>
function filter(params) {
  var select = "SELECT * FROM t",
      where = [],
      bindings = [];
  for (var key in params) {
    where.push(key + " = ?");
    bindings.push(params[key]);
  }
  if (where.length > 0) {
    select += " WHERE " + where.join(" AND ");
  }
  return {"q": select, "params": bindings};
}
</pre>

That's a fairly complicated piece of code, to do very little: no validation, supports AND-only filtering, parameter binding syntax is hardwired... Maintaining a DAL this way is not nice at all.

With node-rdbql, the previous example might be written like this:

<pre>
var sql = require("rdbql").dialect('sqlite3');

function filter(params) {
  var select = sql.select().from("t");
  for (var key in params) {
    select.where($(key + ' = ?', params[key]));
  }
  return {"q": select.toString(), "params": select.params()};
}
</pre>

## More examples of what can be done

[... can be found here](docs/examples.md)

## Formal documentation

* [Introduction](docs/intro.md)
* [Schema definition](docs/schemadef.md)
* [Insert statements](docs/insert.md)
* [Select statements](docs/select.md)
* [Update statements](docs/update.md)
* [delete statements](docs/delete.md)

##  Current TODO list

* add wrappers for column definitions in sql.createTable to have compatible SQL between engines
* test examples with mysql/postgre (and debug as needed)
* write formal documentation
* write examples for more cases (expressions, group by, order by, limit, subselects...)
* make the library usable in the browser

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