2014-10-28 10:18:39 -04:00
|
|
|
#CI-Node-query
|
2014-10-20 16:56:45 -04:00
|
|
|
|
|
|
|
A node query builder for various SQL databases, based on CodeIgniter's query builder.
|
|
|
|
|
2014-10-28 09:05:27 -04:00
|
|
|
[![Build Status](https://travis-ci.org/timw4mail/node-query.svg?branch=master)](https://travis-ci.org/timw4mail/node-query)
|
|
|
|
|
2014-10-28 09:46:27 -04:00
|
|
|
### Supported adapters
|
|
|
|
|
|
|
|
* mysql
|
|
|
|
* mysql2
|
|
|
|
* pg
|
2014-11-03 10:59:18 -05:00
|
|
|
* dblite
|
|
|
|
* sqlite3
|
2014-11-04 12:34:05 -05:00
|
|
|
* node-firebird
|
2014-10-28 09:46:27 -04:00
|
|
|
|
2014-10-28 10:13:15 -04:00
|
|
|
### Installation
|
|
|
|
|
|
|
|
npm install ci-node-query
|
|
|
|
|
2014-10-23 10:53:16 -04:00
|
|
|
### Basic use
|
2014-10-20 16:56:45 -04:00
|
|
|
|
2014-10-28 10:13:15 -04:00
|
|
|
var nodeQuery = require('ci-node-query');
|
2014-10-23 10:53:16 -04:00
|
|
|
|
2014-10-23 11:59:42 -04:00
|
|
|
var connection = ... // Database module connection
|
2014-10-23 10:53:16 -04:00
|
|
|
|
2014-12-01 14:07:29 -05:00
|
|
|
// Three arguments: database type, database connection, database connection library
|
2014-11-03 10:59:18 -05:00
|
|
|
var query = nodeQuery.init('mysql', connection, 'mysql2');
|
|
|
|
|
2014-12-01 14:07:29 -05:00
|
|
|
// The third argument is optional if the database connection library has the same name as the adapter, eg..
|
|
|
|
nodeQuery.init('mysql', connection, 'mysql');
|
|
|
|
// Can be instead
|
|
|
|
nodeQuery.init('mysql', connection);
|
|
|
|
|
2014-11-03 10:59:18 -05:00
|
|
|
// You can also retrieve the instance later
|
|
|
|
query = nodeQuery.getQuery();
|
2014-10-20 16:56:45 -04:00
|
|
|
|
2014-10-23 10:53:16 -04:00
|
|
|
query.select('foo')
|
2014-10-20 16:56:45 -04:00
|
|
|
.from('bar')
|
|
|
|
.where('x', 3)
|
2014-10-27 17:08:18 -04:00
|
|
|
.orWhere({y: 2})
|
2014-10-27 15:47:22 -04:00
|
|
|
.join('baz', 'baz.boo = bar.foo', 'left')
|
2014-10-27 17:08:18 -04:00
|
|
|
.orderBy('x', 'DESC')
|
2014-10-20 16:56:45 -04:00
|
|
|
.limit(2, 3)
|
2014-10-27 15:47:22 -04:00
|
|
|
.get(function(/* Adapter dependent arguments */) {
|
2014-10-23 10:53:16 -04:00
|
|
|
// Database module result handling
|
|
|
|
});
|
2014-10-28 10:18:39 -04:00
|
|
|
|
|
|
|
### Additional help
|
|
|
|
|
|
|
|
* Generated documentation is in the docs/ folder
|
|
|
|
* `tests/query-builder-base.js` contains a lot of usage examples
|
|
|
|
* The `tests/adapters` folder contains examples of how to set up a connection for the appropriate database library
|
2014-10-30 11:10:47 -04:00
|
|
|
* The documentation generated for the latest dev build is also [Available](https://github.timshomepage.net/node-query/docs/)
|
2014-10-20 16:56:45 -04:00
|
|
|
|