Update README

This commit is contained in:
Timothy Warren 2016-02-01 18:55:53 -05:00
parent 11f869b327
commit c4006da1cb

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,23 +22,23 @@ 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();
query.select('foo')
.from('bar') .from('bar')
.where('x', 3) .where('x', 3)
.orWhere({y: 2}) .orWhere({y: 2})
@ -49,8 +49,8 @@ A node query builder for various SQL databases, based on [CodeIgniter](http://ww
// Database module result handling // Database module result handling
}); });
// As of version 3.1.0, you can also get promises // As of version 3.1.0, you can also get promises
var queryPromise = query.select('foo') var queryPromise = query.select('foo')
.from('bar') .from('bar')
.where('x', 3) .where('x', 3)
.orWhere({y: 2}) .orWhere({y: 2})
@ -59,9 +59,10 @@ A node query builder for various SQL databases, based on [CodeIgniter](http://ww
.limit(2, 3) .limit(2, 3)
.get(); .get();
queryPromise.then(function(res) { queryPromise.then(function(res) {
// Handle query results // 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.