diff --git a/.travis.yml b/.travis.yml
index 57b78fb..6d17c6d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,6 +1,4 @@
language: node_js
node_js:
- - "4.1"
- - "4.0"
- - "0.12"
- - "0.10"
+ - "8"
+ - "6"
diff --git a/index.html b/index.html
index 2912377..7341437 100644
--- a/index.html
+++ b/index.html
@@ -495,10 +495,10 @@
select
sel.forUpdate([tbl, ...]) / sel.noWait()
-
Add the FOR UPDATE clause to lock all selected records from all tables in the select (or just the tables specified), along with an optional NO WAIT at the end:
+ Add the FOR UPDATE clause to lock all selected records from all tables in the select (or just the tables specified), along with an optional NOWAIT at the end:
select('addr_id').from('person').forUpdate().of('addr_id').noWait();
-// SELECT addr_id FROM person FOR UPDATE OF addr_id NO WAIT
+// SELECT addr_id FROM person FOR UPDATE OF addr_id NOWAIT
diff --git a/package.json b/package.json
index 3fee40b..33abeb0 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "sql-bricks",
- "version": "2.0.3",
+ "version": "2.0.5",
"author": "Peter Rust ",
"description": "Transparent, Schemaless SQL Generation",
"homepage": "http://csnw.github.io/sql-bricks",
diff --git a/sql-bricks.js b/sql-bricks.js
index dbb1c4b..98891d8 100644
--- a/sql-bricks.js
+++ b/sql-bricks.js
@@ -3,7 +3,7 @@
var is_common_js = typeof exports != 'undefined';
var default_opts = { placeholder: '$%d' };
-
+
var _;
if (is_common_js)
_ = require('underscore');
@@ -23,6 +23,10 @@
if (_.isArray(this.vals[0]))
this.vals = this.vals[0];
}
+ sql.prototype.clone = function clone() {
+ var args = [this.str].concat(this.vals);
+ return sql.apply(null, args);
+ };
sql.setDefaultOpts = setDefaultOpts;
function setDefaultOpts(opts) {
default_opts = _.extend(default_opts, opts);
@@ -108,13 +112,13 @@
if (typeof templ_fn != 'function')
templ_fn = function(opts) { return templ(template, this, opts); };
this.prototype[clause_id + 'ToString'] = templ_fn;
-
+
var index;
if (opts.after || opts.before) {
index = clauses.indexOf(opts.after || opts.before);
if (index == -1)
throw new Error('Error adding clause ' + clause_id + ': dependent clause "' + opts.after + '" not found');
-
+
if (opts.after)
index++;
}
@@ -294,7 +298,7 @@
});
Select.defineClause('orderBy', '{{#if _orderBy}}ORDER BY {{columns _orderBy}}{{/if}}');
- Select.defineClause('forUpdate', '{{#if _forUpdate}}FOR UPDATE{{#if _of}} OF {{columns _of}}{{/if}}{{#if _noWait}} NO WAIT{{/if}}{{/if}}');
+ Select.defineClause('forUpdate', '{{#if _forUpdate}}FOR UPDATE{{#if _of}} OF {{columns _of}}{{/if}}{{#if _noWait}} NOWAIT{{/if}}{{/if}}');
// INSERT statement
@@ -572,7 +576,7 @@
// Debt: Determining whether join is natural/cross by reading the string is slightly hacky... but works.
if (/^(natural|cross)/i.test(this.type))
return this.type + ' JOIN ' + tbl;
-
+
// Not a natural or cross, check for criteria.
if (!on || _.isEmpty(on)) {
if (sql._joinCriteria) {
@@ -802,7 +806,7 @@
sql = handleValues(this.list, opts).join(', ');
else if (this.list instanceof Statement)
sql = this.list._toString(opts);
-
+
return col_sql + ' IN (' + sql + ')';
};
@@ -958,7 +962,7 @@
// auto-quote tbl & col names if they have caps or are reserved words
sql._autoQuoteChar = '"';
-
+
function autoQuote(str) {
if (/^\w+$/.test(str) && (/[A-Z]/.test(str) || str in reserved))
return sql._autoQuoteChar + str + sql._autoQuoteChar;
@@ -1104,7 +1108,7 @@
function cls() {
if (!(this instanceof cls))
return applyNew(cls, arguments);
-
+
base.apply(this, arguments);
}
return inherits(cls, base);
diff --git a/tests/doctests.js b/tests/doctests.js
index 3e1eb84..146b08b 100644
--- a/tests/doctests.js
+++ b/tests/doctests.js
@@ -161,7 +161,7 @@ check(select().from('person').where({'last_name': 'Flintstone'}).union()
.sele
});
it("select('addr_id').from('person').forUpdate().of('addr_id').noWait();", function() {
-check(select('addr_id').from('person').forUpdate().of('addr_id').noWait(), "SELECT addr_id FROM person FOR UPDATE OF addr_id NO WAIT");
+check(select('addr_id').from('person').forUpdate().of('addr_id').noWait(), "SELECT addr_id FROM person FOR UPDATE OF addr_id NOWAIT");
});
it("insert('person', {'first_name': 'Fred', 'last_name': 'Flintstone'});", function() {
diff --git a/tests/tests.js b/tests/tests.js
index 650d586..1d2c706 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -402,9 +402,9 @@ describe('SQL Bricks', function() {
check(select().from('user').forUpdate().of('user'),
'SELECT * FROM "user" FOR UPDATE OF "user"');
});
- it('should support FOR UPDATE OF ... NO WAIT', function() {
+ it('should support FOR UPDATE OF ... NOWAIT', function() {
check(select().from('user').forUpdate().of('user').noWait(),
- 'SELECT * FROM "user" FOR UPDATE OF "user" NO WAIT');
+ 'SELECT * FROM "user" FOR UPDATE OF "user" NOWAIT');
});
});
@@ -948,6 +948,15 @@ describe('SQL Bricks', function() {
sel.clone().where('last_name', 'Flintstone');
check(sel, "SELECT * FROM \"user\" WHERE first_name IN (SELECT first_name FROM \"user\")");
});
+ it('should clone parameterized sub-expressions', function() {
+ checkParams(select().from('tbl').where(or(sql('a = $1', 444), sql('b = $1', 555), sql('c = $1', 666))).clone(),
+ 'SELECT * FROM tbl WHERE a = $1 OR b = $2 OR c = $3',
+ [444, 555, 666]);
+ });
+ it('should clone non-parameterized sub-expressions', function() {
+ check(select().from('tbl').where(or(sql('a = 444'), sql('b = 555'), sql('c = 666'))).clone(),
+ 'SELECT * FROM tbl WHERE a = 444 OR b = 555 OR c = 666');
+ });
});
describe('the AS keyword', function() {