Update README

This commit is contained in:
Timothy Warren 2016-02-01 18:55:53 -05:00
parent 11f869b327
commit c4006da1cb
1 changed files with 36 additions and 35 deletions

View File

@ -1,4 +1,4 @@
#CI-Node-query # CI-Node-query
A node query builder for various SQL databases, based on [CodeIgniter](http://www.codeigniter.com/user_guide/database/query_builder.html)'s query builder. A node query builder for various SQL databases, based on [CodeIgniter](http://www.codeigniter.com/user_guide/database/query_builder.html)'s query builder.
@ -22,47 +22,48 @@ A node query builder for various SQL databases, based on [CodeIgniter](http://ww
[![NPM](https://nodei.co/npm/ci-node-query.png?downloads=true&downloadRank=true)](https://nodei.co/npm/ci-node-query/) [![NPM](https://nodei.co/npm/ci-node-query.png?downloads=true&downloadRank=true)](https://nodei.co/npm/ci-node-query/)
### Basic use ### Basic use
```javascript
var nodeQuery = require('ci-node-query');
var nodeQuery = require('ci-node-query'); var connection = ... // Database module connection
var connection = ... // Database module connection // Three arguments: database type, database connection, database connection library
var query = nodeQuery.init('mysql', connection, 'mysql2');
// Three arguments: database type, database connection, database connection library // The third argument is optional if the database connection library has the same name as the adapter, eg..
var query = nodeQuery.init('mysql', connection, 'mysql2'); nodeQuery.init('mysql', connection, 'mysql');
// Can be instead
nodeQuery.init('mysql', connection);
// The third argument is optional if the database connection library has the same name as the adapter, eg.. // You can also retrieve the instance later
nodeQuery.init('mysql', connection, 'mysql'); query = nodeQuery.getQuery();
// Can be instead
nodeQuery.init('mysql', connection);
// You can also retrieve the instance later query.select('foo')
query = nodeQuery.getQuery(); .from('bar')
.where('x', 3)
query.select('foo') .orWhere({y: 2})
.from('bar') .join('baz', 'baz.boo = bar.foo', 'left')
.where('x', 3) .orderBy('x', 'DESC')
.orWhere({y: 2}) .limit(2, 3)
.join('baz', 'baz.boo = bar.foo', 'left') .get(function(/* Adapter dependent arguments */) {
.orderBy('x', 'DESC') // Database module result handling
.limit(2, 3)
.get(function(/* Adapter dependent arguments */) {
// Database module result handling
});
// As of version 3.1.0, you can also get promises
var queryPromise = query.select('foo')
.from('bar')
.where('x', 3)
.orWhere({y: 2})
.join('baz', 'baz.boo = bar.foo', 'left')
.orderBy('x', 'DESC')
.limit(2, 3)
.get();
queryPromise.then(function(res) {
// Handle query results
}); });
// As of version 3.1.0, you can also get promises
var queryPromise = query.select('foo')
.from('bar')
.where('x', 3)
.orWhere({y: 2})
.join('baz', 'baz.boo = bar.foo', 'left')
.orderBy('x', 'DESC')
.limit(2, 3)
.get();
queryPromise.then(function(res) {
// Handle query results
});
```
### Security notes ### Security notes
As of version 2, `where` and `having` type methods parse the values passed to look for function calls. While values passed are still passed as query parameters, take care to avoid passing these kinds of methods unfiltered input. SQL function arguments are not currently parsed, so they need to be properly escaped for the current database. As of version 2, `where` and `having` type methods parse the values passed to look for function calls. While values passed are still passed as query parameters, take care to avoid passing these kinds of methods unfiltered input. SQL function arguments are not currently parsed, so they need to be properly escaped for the current database.