From 439630cddaa34b33c47893e45ca99d16ab62c9f7 Mon Sep 17 00:00:00 2001
From: "Timothy J. Warren"
Date: Thu, 30 Oct 2014 09:48:55 -0400
Subject: [PATCH] Update docs and npm version
---
docs/adapter.js.html | 2 +-
docs/driver.js.html | 43 +++++-
docs/helpers.js.html | 2 +-
docs/index.html | 2 +-
docs/module-adapter.html | 2 +-
docs/module-driver.html | 2 +-
docs/module-helpers.html | 2 +-
docs/module-node-query.html | 2 +-
docs/module-query-builder.html | 254 ++++++++++++++++++++++++++++-----
docs/module-query-parser.html | 2 +-
docs/modules.list.html | 2 +-
docs/node-query.js.html | 2 +-
docs/query-builder.js.html | 29 +++-
docs/query-parser.js.html | 2 +-
package.json | 2 +-
15 files changed, 300 insertions(+), 50 deletions(-)
diff --git a/docs/adapter.js.html b/docs/adapter.js.html
index 18323a2..24cac96 100644
--- a/docs/adapter.js.html
+++ b/docs/adapter.js.html
@@ -110,7 +110,7 @@ module.exports = {
Documentation generated by JSDoc 3.3.0-alpha9
- on Tue Oct 28th 2014 using the DocStrap template.
diff --git a/docs/driver.js.html b/docs/driver.js.html
index 00ee283..5318609 100644
--- a/docs/driver.js.html
+++ b/docs/driver.js.html
@@ -187,7 +187,48 @@ var d = {
sql += d.quoteTable(table);
return sql;
+ },
+
+ /**
+ * SQL to insert a group of rows
+ *
+ * @param {String} table - The table to insert to
+ * @param {Array} [data] - The array of object containing data to insert
+ * @return {String}
+ */
+ insertBatch: function(table, data) {
+
+ // Get the data values to insert, so they can
+ // be parameterized
+ var vals = [];
+ data.forEach(function(obj) {
+ Object.keys(obj).forEach(function(key) {
+ vals.push(obj[key]);
+ });
+ });
+
+ // Get the field names from the keys of the first
+ // object inserted
+ var fields = Object.keys(data[0]);
+ table = d.quoteTable(table);
+
+ var sql = "INSERT INTO " + table + " ("
+ + d.quoteIdentifiers(fields).join(",")
+ + ") VALUES ";
+
+ // Create placeholder groups
+ var params = new Array(fields.length).fill('?');
+ var paramString = "(" + params.join(',') + ")";
+ var paramList = new Array(data.length).fill(paramString);
+
+ sql += paramList.join(',');
+
+ return {
+ sql: sql,
+ values: vals
+ };
}
+
};
module.exports = d;
@@ -211,7 +252,7 @@ module.exports = d;
Documentation generated by JSDoc 3.3.0-alpha9
- on Tue Oct 28th 2014 using the DocStrap template.
diff --git a/docs/helpers.js.html b/docs/helpers.js.html
index 9ad6104..284233f 100644
--- a/docs/helpers.js.html
+++ b/docs/helpers.js.html
@@ -168,7 +168,7 @@ module.exports = h;
Documentation generated by JSDoc 3.3.0-alpha9
- on Tue Oct 28th 2014 using the DocStrap template.
diff --git a/docs/index.html b/docs/index.html
index 14cb910..eeed6be 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -141,7 +141,7 @@ query.select('foo')
Documentation generated by JSDoc 3.3.0-alpha9
- on Tue Oct 28th 2014 using the DocStrap template.
diff --git a/docs/module-adapter.html b/docs/module-adapter.html
index a7cce8b..4b8aeee 100644
--- a/docs/module-adapter.html
+++ b/docs/module-adapter.html
@@ -354,7 +354,7 @@
Documentation generated by JSDoc 3.3.0-alpha9
- on Tue Oct 28th 2014 using the DocStrap template.
diff --git a/docs/module-driver.html b/docs/module-driver.html
index 889c66c..cf9e4b9 100644
--- a/docs/module-driver.html
+++ b/docs/module-driver.html
@@ -170,7 +170,7 @@
Documentation generated by JSDoc 3.3.0-alpha9
- on Tue Oct 28th 2014 using the DocStrap template.
diff --git a/docs/module-helpers.html b/docs/module-helpers.html
index dba6e08..ead6b11 100644
--- a/docs/module-helpers.html
+++ b/docs/module-helpers.html
@@ -686,7 +686,7 @@ function name, eg isNumber
Documentation generated by JSDoc 3.3.0-alpha9
- on Tue Oct 28th 2014 using the DocStrap template.
diff --git a/docs/module-node-query.html b/docs/module-node-query.html
index 1c5ba0a..d53c188 100644
--- a/docs/module-node-query.html
+++ b/docs/module-node-query.html
@@ -358,7 +358,7 @@
Documentation generated by JSDoc 3.3.0-alpha9
- on Tue Oct 28th 2014 using the DocStrap template.
diff --git a/docs/module-query-builder.html b/docs/module-query-builder.html
index 227770c..1c9d7cb 100644
--- a/docs/module-query-builder.html
+++ b/docs/module-query-builder.html
@@ -383,7 +383,7 @@
@@ -519,7 +519,7 @@
@@ -764,7 +764,7 @@
@@ -955,7 +955,7 @@
@@ -1154,7 +1154,7 @@
@@ -1355,7 +1355,7 @@
@@ -1546,7 +1546,7 @@
@@ -1641,7 +1641,7 @@
@@ -1788,7 +1788,7 @@
@@ -1875,7 +1875,7 @@
@@ -1962,7 +1962,7 @@
@@ -2147,7 +2147,7 @@
@@ -2357,7 +2357,7 @@
@@ -2393,6 +2393,194 @@
+
+
+
+
+
+ insertBatch(table, data, callback)
+
+
+
+
+
+
+
+
Insert multiple sets of rows at a time
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name |
+
+
+ Type |
+
+
+
+
+
+ Description |
+
+
+
+
+
+
+
+
+ table |
+
+
+
+
+
+String
+
+
+
+ |
+
+
+
+
+
+ The table to insert into |
+
+
+
+
+
+
+ data |
+
+
+
+
+
+Array
+
+
+
+ |
+
+
+
+
+
+ The array of objects containing data rows to insert |
+
+
+
+
+
+
+ callback |
+
+
+
+
+
+function
+
+
+
+ |
+
+
+
+
+
+ Callback for handling database response |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+ -
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Returns:
+
+
+
+
+
+
+
+
+
+
+ Example
+
+ query.insertBatch('foo',[{id:1,val:'bar'},{id:2,val:'baz'}], callbackFunction);S
+
+
+
@@ -2583,7 +2771,7 @@
@@ -2809,7 +2997,7 @@
@@ -2988,7 +3176,7 @@
@@ -3214,7 +3402,7 @@
@@ -3405,7 +3593,7 @@
@@ -3493,7 +3681,7 @@ prefixed with 'OR'
@@ -3678,7 +3866,7 @@ prefixed with 'OR'
@@ -3904,7 +4092,7 @@ prefixed with 'OR'
@@ -3992,7 +4180,7 @@ prefixed with 'OR NOT'
@@ -4218,7 +4406,7 @@ prefixed with 'OR NOT'
@@ -4403,7 +4591,7 @@ prefixed with 'OR NOT'
@@ -4562,7 +4750,7 @@ prefixed with 'OR NOT'
@@ -4721,7 +4909,7 @@ prefixed with 'OR NOT'
@@ -4860,7 +5048,7 @@ prefixed with 'OR NOT'
@@ -5042,7 +5230,7 @@ prefixed with 'OR NOT'
@@ -5252,7 +5440,7 @@ prefixed with 'OR NOT'
@@ -5437,7 +5625,7 @@ prefixed with 'OR NOT'
@@ -5596,7 +5784,7 @@ prefixed with 'OR NOT'
@@ -5755,7 +5943,7 @@ prefixed with 'OR NOT'
@@ -5819,7 +6007,7 @@ prefixed with 'OR NOT'
Documentation generated by JSDoc 3.3.0-alpha9
- on Tue Oct 28th 2014 using the DocStrap template.
diff --git a/docs/module-query-parser.html b/docs/module-query-parser.html
index 35e4f43..386a54e 100644
--- a/docs/module-query-parser.html
+++ b/docs/module-query-parser.html
@@ -466,7 +466,7 @@
Documentation generated by JSDoc 3.3.0-alpha9
- on Tue Oct 28th 2014 using the DocStrap template.
diff --git a/docs/modules.list.html b/docs/modules.list.html
index f09a73f..4aee28e 100644
--- a/docs/modules.list.html
+++ b/docs/modules.list.html
@@ -158,7 +158,7 @@
Documentation generated by JSDoc 3.3.0-alpha9
- on Tue Oct 28th 2014 using the DocStrap template.
diff --git a/docs/node-query.js.html b/docs/node-query.js.html
index b72995c..f6457c9 100644
--- a/docs/node-query.js.html
+++ b/docs/node-query.js.html
@@ -129,7 +129,7 @@ module.exports = nodeQuery.init;
Documentation generated by JSDoc 3.3.0-alpha9
- on Tue Oct 28th 2014 using the DocStrap template.
diff --git a/docs/query-builder.js.html b/docs/query-builder.js.html
index c020328..8730819 100644
--- a/docs/query-builder.js.html
+++ b/docs/query-builder.js.html
@@ -344,18 +344,21 @@ var QueryBuilder = function(driver, adapter) {
_p.appendMap(args.conj, str, 'whereIn');
},
run: function(type, table, callback, sql, vals) {
+
if ( ! sql)
{
sql = _p.compile(type, table);
}
-//console.log(sql);
-//console.log('------------------------');
if ( ! vals)
{
vals = state.values.concat(state.whereValues);
}
+//console.log(sql);
+//console.log(vals);
+//console.log('------------------------');
+
// Reset the state so another query can be built
_p.resetState();
@@ -838,6 +841,7 @@ var QueryBuilder = function(driver, adapter) {
*/
this.insert = function(/* table, data, callback */) {
var args = getArgs('table:string, [data]:object, callback:function', arguments);
+ args.table = driver.quoteTable(args.table);
if (args.data) {
this.set(args.data);
}
@@ -846,6 +850,23 @@ var QueryBuilder = function(driver, adapter) {
_p.run('insert', args.table, args.callback);
};
+ /**
+ * Insert multiple sets of rows at a time
+ *
+ * @param {String} table - The table to insert into
+ * @param {Array} data - The array of objects containing data rows to insert
+ * @param {Function} callback - Callback for handling database response
+ * @example query.insertBatch('foo',[{id:1,val:'bar'},{id:2,val:'baz'}], callbackFunction);S
+ * @return void
+ */
+ this.insertBatch = function(/* table, data, callback */) {
+ var args = getArgs('table:string, data:array, callback:function', arguments);
+ var batch = driver.insertBatch(args.table, args.data);
+
+ // Run the query
+ _p.run('', '', args.callback, batch.sql, batch.values);
+ };
+
/**
* Run the generated update query
*
@@ -873,7 +894,7 @@ var QueryBuilder = function(driver, adapter) {
* @return void
*/
this.delete = function (/*table, [where], callback*/) {
- var args = getArgs('table:string, [where], callback:function', arguments);
+ var args = getArgs('table:string, [where]:object, callback:function', arguments);
if (args.where)
{
@@ -962,7 +983,7 @@ module.exports = QueryBuilder;
Documentation generated by JSDoc 3.3.0-alpha9
- on Tue Oct 28th 2014 using the DocStrap template.
diff --git a/docs/query-parser.js.html b/docs/query-parser.js.html
index dc70519..ed6a40c 100644
--- a/docs/query-parser.js.html
+++ b/docs/query-parser.js.html
@@ -187,7 +187,7 @@ module.exports = QueryParser;
Documentation generated by JSDoc 3.3.0-alpha9
- on Tue Oct 28th 2014 using the DocStrap template.
diff --git a/package.json b/package.json
index 09ce758..b7659e7 100755
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "ci-node-query",
- "version": "0.0.4",
+ "version": "0.1.0",
"description": "A query builder for node based on the one in CodeIgniter",
"author": "Timothy J Warren ",
"engines": {