# querybuilder

> Module to create SQL and NoSQL queries.

Latest version **1.1.0** (published 2013-05-29) · MIT license · 0 weekly downloads

## Install

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

## 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.1.0 |
| Published | 2013-05-29 |
| First published | 2013-03-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | * |
| Dependencies | 1 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Marc Riegel |
| Maintainers | mrcrgl |
| Keywords | sql, nosql, query builder, chaining |

## Links

- npm: https://www.npmjs.com/package/querybuilder
- Repository: https://github.com/mrcrgl/node-querybuilder
- Issues: https://github.com/mrcrgl/node-querybuilder/issues
- npm.io page: https://npm.io/package/querybuilder

## Dependencies (1)

- [mongodb](https://npm.io/package/mongodb.md) 1.x

## 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

- 1.1.0 (latest) — 2013-05-29
- 1.0.4 — 2013-04-30
- 1.0.3 — 2013-04-30
- 1.0.2 — 2013-04-23
- 1.0.1 — 2013-03-27
- 1.0.0 — 2013-03-04

## README

node-querybuilder
=================

Querybuilder have a simple, mongo like, API to create SQL and NoSQL queries. 

## Install
```bash
$ npm install querybuilder
```

## Supported storages / client libs

* MongoDB (Tested with [node-mongodb-native](https://github.com/mongodb/node-mongodb-native))
* MySQL (Tested with [node-mysql](https://github.com/felixge/node-mysql))

## API

### Create NoSQL query (MongoDB)

```javascript
var Querybuilder = require('querybuilder');
var qb = new Querybuilder('mongodb');

// Synchronous
var query = qb.select('*')
              .where({name: 'horst'})
              .offset(5)
              .call();
/* <- returns: 
{ type: 'select',
  what: undefined,
  where: { name: 'horst' },
  limit: 50,
  skip: 5,
  sort: {},
  set: {} }
*/

// Asynchronous
// Define a handler. We simply forward the query to the callback
qb.handler(function(query, callback) {
  
    // Your SQL connection can be placed here
    callback(null, query);
});

qb.select('*')
  .from('users') // just for campability to mysql
  .where({name: 'horst'})
  .offset(5)
  .call(function(err, query) {
    if (err) throw new Error(err);
    
    console.dir(query);
    // <- equal to synchronous
});
```

### Create SQL query (MySQL)

```javascript

var Querybuilder = require('querybuilder');
var qb = new Querybuilder('mysql');

// Synchronous
var query = qb.select('*')
              .from('users')
              .where({name: 'horst'})
              .offset(5)
              .call();
// <- returns: 'SELECT * FROM `users` WHERE (`name` = \'horst\') LIMIT 50,5'


// Asynchronous
// Define a handler. We simply forward the query to the callback
qb.handler(function(query, callback) {
  
    // Your SQL connection can be placed here
    callback(null, query);
});

qb.select('*')
  .from('users')
  .where({name: 'horst'})
  .offset(5)
  .call(function(err, query) {
    if (err) throw new Error(err);
    
    console.dir(query);
    // <- equal to synchronous
});
```

Module under MIT Licence

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