diff --git a/API.md b/API.md index 2fc0bb5..4fd79c7 100644 --- a/API.md +++ b/API.md @@ -61,10 +61,9 @@ Run an arbitrary sql query. Run as a prepared statement. **Parameters** - `sql` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The sql to execute -- `params` **\[[array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)]** The query parameters -- `callback` **\[[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)]** Optional callback +- `params` **\[[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)]** The query parameters -Returns **(void | [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise))** Returns a promise if no callback is supplied +Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** Promise with result of query ## resetQuery @@ -79,7 +78,6 @@ Empties the selected database table **Parameters** - `table` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the name of the table to truncate -- `callback` **\[[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)]** Optional callback Returns **(void | [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise))** Returns a promise if no callback is supplied @@ -405,7 +403,6 @@ Get the results of the compiled query - `table` **\[[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]** The table to select from - `limit` **\[[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)]** A limit for the query - `offset` **\[[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)]** An offset for the query -- `callback` **\[[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)]** A callback for receiving the result **Examples** @@ -414,11 +411,11 @@ query.get('table_name').then(promiseCallback); // Get all the rows in the table ``` ```javascript -query.get('table_name', 5, callback); // Get 5 rows from the table +query.get('table_name', 5); // Get 5 rows from the table ``` ```javascript -query.get(callback); // Get the results of a query generated with other methods +query.get(); // Get the results of a query generated with other methods ``` Returns **(void | [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise))** If no callback is passed, a promise is returned @@ -431,9 +428,8 @@ Run the generated insert query - `table` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The table to insert into - `data` **\[[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)]** Data to insert, if not already added with the 'set' method -- `callback` **\[[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)]** Callback for handling response from the database -Returns **(void | [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise))** If no callback is passed, a promise is returned +Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** If no callback is passed, a promise is returned ## insertBatch @@ -443,20 +439,15 @@ Insert multiple sets of rows at a time - `table` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The table to insert into - `data` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)** The array of objects containing data rows to insert -- `callback` **\[[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)]** Callback for handling database response **Examples** -```javascript -query.insertBatch('foo',[{id:1,val:'bar'},{id:2,val:'baz'}], callbackFunction); -``` - ```javascript query.insertBatch('foo',[{id:1,val:'bar'},{id:2,val:'baz'}]) .then(promiseCallback); ``` -Returns **(void | [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise))** If no callback is passed, a promise is returned +Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** If no callback is passed, a promise is returned ## update @@ -466,9 +457,8 @@ Run the generated update query - `table` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The table to insert into - `data` **\[[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)]** Data to insert, if not already added with the 'set' method -- `callback` **\[[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)]** Callback for handling response from the database -Returns **(void | [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise))** If no callback is passed, a promise is returned +Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** If no callback is passed, a promise is returned ## delete @@ -478,9 +468,8 @@ Run the generated delete query - `table` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The table to insert into - `where` **\[[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)]** Where clause for delete statement -- `callback` **\[[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)]** Callback for handling response from the database -Returns **(void | [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise))** If no callback is passed, a promise is returned +Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** If no callback is passed, a promise is returned ## getCompiledSelect diff --git a/CHANGELOG.md b/CHANGELOG.md index 94b7191..321bae3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +# 5.0.0 +* Re-added firebird as a database +* Replaced all callback interfaces with promises + ## 4.0.0 * Changed connection setup to just use a config object - the appropriate adapter object is created by the library. * Removed mysql adapter, as mysql2 is very similar and does proper prepared statements @@ -11,4 +15,4 @@ * Added back tests for `node-firebird` adapter. Using this adapter with promises is not currently supported. ## 3.1.0 -* Added support for promises on query execution methods \ No newline at end of file +* Added support for promises on query execution methods diff --git a/README.md b/README.md index 7b89667..0d514c2 100755 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ A node query builder for various SQL databases, based on [CodeIgniter](http://ww ### Supported databases +* Firebird (via `node-firebird`) * Mysql (via `mysql2`) * PostgreSQL (via `pg`) * Sqlite (via `dblite`) @@ -38,18 +39,8 @@ const nodeQuery = require('ci-node-query')({ // Get the query builder const query = nodeQuery.getQuery(); -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(function(err, result) { - // Handle Results Here - }); - // As of version 3.1.0, you can also get promises +// Version 5.0.0 removes all callback interfaces const queryPromise = query.select('foo') .from('bar') .where('x', 3) diff --git a/docs/index.html b/docs/index.html index 7110b98..6431149 100644 --- a/docs/index.html +++ b/docs/index.html @@ -364,10 +364,12 @@
let nodeQuery = require('ci-node-query')({
- driver: 'mysql',
- connection: {
- host: 'localhost',
- user: 'root',
- password: '',
- database: 'mysql'
+ driver: 'mysql',
+ connection: {
+ host: 'localhost',
+ user: 'root',
+ password: '',
+ database: 'mysql'
}
});
let nodeQuery = require('ci-node-query')({
- driver: 'sqlite',
- connection: ':memory:'
+ driver: 'sqlite',
+ connection: ':memory:'
});
@@ -558,10 +560,12 @@
Run an arbitrary sql query. Run as a prepared statement.
- + @@ -661,15 +665,7 @@([array])
The query parameters
-
- (void | Promise)
:
- Returns a promise if no callback is supplied
+ Promise
:
+ Promise with result of query
@@ -738,6 +734,7 @@
void
:
+
@@ -760,7 +757,7 @@
Empties the selected database table
- + @@ -793,14 +790,6 @@([function])
Optional callback
-
- void
:
+
@@ -1044,7 +1034,7 @@
- Add a 'like/ and like' clause to the query
+Add a 'like/ and like' clause to the query
@@ -1128,7 +1118,7 @@ -Add a 'not like/ and not like' clause to the query
+Add a 'not like/ and not like' clause to the query
@@ -1212,7 +1202,7 @@ -Add an 'or like' clause to the query
+Add an 'or like' clause to the query
@@ -1296,7 +1286,7 @@ -Add an 'or not like' clause to the query
+Add an 'or not like' clause to the query
@@ -1380,7 +1370,7 @@ -Add a 'having' clause
+Add a 'having' clause
@@ -1454,7 +1444,7 @@ -Add an 'or having' clause
+Add an 'or having' clause
@@ -1528,7 +1518,7 @@ -Set a 'where' clause
+Set a 'where' clause
@@ -1602,7 +1592,7 @@ -Set a 'or where' clause
+Set a 'or where' clause
@@ -1808,7 +1798,7 @@ -Field is null prefixed with 'OR'
+Field is null prefixed with 'OR'
Field is not null prefixed with 'OR'
+Field is not null prefixed with 'OR'
Set a 'where in' clause
+Set a 'where in' clause
@@ -2014,7 +2004,7 @@ -Set a 'or where in' clause
+Set a 'or where in' clause
@@ -2088,7 +2078,7 @@ -Set a 'where not in' clause
+Set a 'where not in' clause
@@ -2162,7 +2152,7 @@ -Set a 'or where not in' clause
+Set a 'or where not in' clause
@@ -2293,7 +2283,7 @@query.set('foo', 'bar'); // Set a key, value pair
- query.set({foo:'bar'}); // Set with an object
+ query.set({foo:'bar'}); // Set with an object
@@ -2673,7 +2663,7 @@
Adds an open paren to the current query for logical grouping, -prefixed with 'OR'
+prefixed with 'OR'Adds an open paren to the current query for logical grouping, -prefixed with 'OR NOT'
+prefixed with 'OR NOT'Get the results of the compiled query
- + @@ -2874,14 +2864,6 @@ prefixed with 'OR NOT'([Function])
A callback for receiving the result
-
- query.get('table_name').then(promiseCallback); // Get all the rows in the table
- query.get('table_name', 5, callback); // Get 5 rows from the table
+ query.get('table_name', 5); // Get 5 rows from the table
- query.get(callback); // Get the results of a query generated with other methods
+ query.get(); // Get the results of a query generated with other methods
@@ -2927,7 +2909,7 @@ prefixed with 'OR NOT'
Run the generated insert query
- + @@ -2962,15 +2944,7 @@ prefixed with 'OR NOT'([Object])
Data to insert, if not already added with the 'set' method
-
- ([Function])
Callback for handling response from the database
+ data ([Object])
Data to insert, if not already added with the 'set' method
(void | Promise)
:
+ Promise
:
If no callback is passed, a promise is returned
@@ -3009,7 +2983,7 @@ prefixed with 'OR NOT'
Insert multiple sets of rows at a time
- + @@ -3050,14 +3024,6 @@ prefixed with 'OR NOT'([Function])
Callback for handling database response
-
- (void | Promise)
:
+ Promise
:
If no callback is passed, a promise is returned
@@ -3079,10 +3045,7 @@ prefixed with 'OR NOT'
query.insertBatch('foo',[{id:1,val:'bar'},{id:2,val:'baz'}], callbackFunction);
-
-
- query.insertBatch('foo',[{id:1,val:'bar'},{id:2,val:'baz'}])
+ query.insertBatch('foo',[{id:1,val:'bar'},{id:2,val:'baz'}])
.then(promiseCallback);
@@ -3101,7 +3064,7 @@ prefixed with 'OR NOT'
@@ -3112,7 +3075,7 @@ prefixed with 'OR NOT'
Run the generated update query
-
+
@@ -3136,15 +3099,7 @@ prefixed with 'OR NOT'
- data ([Object])
Data to insert, if not already added with the 'set' method
-
-
-
-
-
-
-
- callback ([Function])
Callback for handling response from the database
+ data ([Object])
Data to insert, if not already added with the 'set' method
@@ -3158,7 +3113,7 @@ prefixed with 'OR NOT'
Returns
- (void | Promise)
:
+ Promise
:
If no callback is passed, a promise is returned
@@ -3183,7 +3138,7 @@ prefixed with 'OR NOT'
@@ -3194,7 +3149,7 @@ prefixed with 'OR NOT'
Run the generated delete query
-
+
@@ -3224,14 +3179,6 @@ prefixed with 'OR NOT'
-
-
- callback ([Function])
Callback for handling response from the database
-
-
-
-
-
@@ -3240,7 +3187,7 @@ prefixed with 'OR NOT'
Returns
- (void | Promise)
:
+ Promise
:
If no callback is passed, a promise is returned
@@ -3579,10 +3526,12 @@ prefixed with 'OR NOT'
+
Result
+