mirror of
https://github.com/knex/knex.git
synced 2025-11-14 09:03:44 +00:00
fixing issues with improper queuing on the schema queries
This commit is contained in:
parent
4e57b8d5a9
commit
cbc25c62fa
@ -28,6 +28,7 @@ _.extend(MysqlClient.prototype, base.protoProps, {
|
|||||||
// Call the querystring and then release the client
|
// Call the querystring and then release the client
|
||||||
conn.query(builder.sql, builder.bindings, function (err, resp) {
|
conn.query(builder.sql, builder.bindings, function (err, resp) {
|
||||||
if (err) { return dfd.reject(err); }
|
if (err) { return dfd.reject(err); }
|
||||||
|
|
||||||
if (builder._source === 'SchemaBuilder') {
|
if (builder._source === 'SchemaBuilder') {
|
||||||
if (builder.type === 'tableExists') {
|
if (builder.type === 'tableExists') {
|
||||||
if (resp.length > 0) return dfd.resolve(_.pick(resp, _.keys(resp)));
|
if (resp.length > 0) return dfd.resolve(_.pick(resp, _.keys(resp)));
|
||||||
|
|||||||
@ -455,8 +455,6 @@ SqliteDB('users')
|
|||||||
|
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<h3>Additional Where Methods:</h3>
|
<h3>Additional Where Methods:</h3>
|
||||||
|
|
||||||
<ul class="small">
|
<ul class="small">
|
||||||
@ -599,7 +597,7 @@ Knex('users')
|
|||||||
<b class="header">del / delete</b><code>.del()</code>
|
<b class="header">del / delete</b><code>.del()</code>
|
||||||
<br />
|
<br />
|
||||||
Aliased to <tt>del</tt> as <tt>delete</tt> is a reserved word in javascript, this method deletes
|
Aliased to <tt>del</tt> as <tt>delete</tt> is a reserved word in javascript, this method deletes
|
||||||
one or more rows, based on the conditions specified in the query.
|
one or more rows, based on the other conditions specified in the query.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p id="Builder-count">
|
<p id="Builder-count">
|
||||||
|
|||||||
37
knex.js
37
knex.js
@ -1,4 +1,4 @@
|
|||||||
// Knex.js 0.1.0
|
// Knex.js 0.0.0
|
||||||
//
|
//
|
||||||
// (c) 2013 Tim Griesser
|
// (c) 2013 Tim Griesser
|
||||||
// Knex may be freely distributed under the MIT license.
|
// Knex may be freely distributed under the MIT license.
|
||||||
@ -23,7 +23,7 @@
|
|||||||
Knex.VERSION = '0.0.0';
|
Knex.VERSION = '0.0.0';
|
||||||
|
|
||||||
// Methods common to both the `Grammar` and `SchemaGrammar` interfaces,
|
// Methods common to both the `Grammar` and `SchemaGrammar` interfaces,
|
||||||
// that is used to generate the sql in one form or another.
|
// used to generate the sql in one form or another.
|
||||||
var Common = {
|
var Common = {
|
||||||
|
|
||||||
_debug: false,
|
_debug: false,
|
||||||
@ -1450,24 +1450,29 @@
|
|||||||
// Prep the SQL associated with the builder.
|
// Prep the SQL associated with the builder.
|
||||||
builder.sql = builder.toSql();
|
builder.sql = builder.toSql();
|
||||||
builder.bindings = builder._cleanBindings();
|
builder.bindings = builder._cleanBindings();
|
||||||
|
if (!_.isArray(builder.sql)) builder.sql = [builder.sql];
|
||||||
|
|
||||||
// Used to handle the schema builder cases, where there is an array of
|
var chain;
|
||||||
// sql statements used in the table creation. These definitely need
|
for (var i = 0, l = builder.sql.length; i < l; i++) {
|
||||||
// to be processed on the same connection.
|
if (chain) {
|
||||||
if (_.isArray(builder.sql)) {
|
chain.then(multiQuery(builder, i, chain));
|
||||||
var emptyConnection = !builder._connection;
|
} else {
|
||||||
return Q.resolve(builder._connection || builder.client.getConnection()).then(function(conn) {
|
chain = multiQuery(builder, i);
|
||||||
builder._connection = conn;
|
}
|
||||||
return _.reduce(builder.sql, function(memo, sql) {
|
|
||||||
return memo.then(function () { builder.client.query(_.extend({}, builder, {sql: sql})); });
|
|
||||||
}, Q.resolve()).fin(function() {
|
|
||||||
if (emptyConnection) builder.client.pool.release(conn);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Query on the query builder, which should resolve with a promise.
|
// Query on the query builder, which should resolve with a promise.
|
||||||
return builder.client.query(builder);
|
return chain;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Sets up a multi-query
|
||||||
|
var multiQuery = function(builder, i, chain) {
|
||||||
|
if (chain) {
|
||||||
|
return function() {
|
||||||
|
return multiQuery(builder, i);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return builder.client.query(_.extend({}, builder, {sql: builder.sql[i]}));
|
||||||
};
|
};
|
||||||
|
|
||||||
// Knex.Initialize
|
// Knex.Initialize
|
||||||
|
|||||||
@ -19,7 +19,7 @@
|
|||||||
"generic-pool": "~2.0.3"
|
"generic-pool": "~2.0.3"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "mocha -b -R spec test/index.js"
|
"test": "mocha -R spec test/index.js"
|
||||||
},
|
},
|
||||||
"repository": "https://github.com/tgriesser/knex",
|
"repository": "https://github.com/tgriesser/knex",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
var Q = require('q');
|
var Q = require('q');
|
||||||
module.exports = function(Knex, handler, error) {
|
module.exports = function(Knex, handler, error, type, db) {
|
||||||
|
|
||||||
var res = null;
|
var res = null;
|
||||||
return Q.all([
|
return Q.all([
|
||||||
|
|||||||
@ -14,7 +14,7 @@ module.exports = function(Knex, type) {
|
|||||||
before(function(ok) {
|
before(function(ok) {
|
||||||
var val = handler(type, 'schema');
|
var val = handler(type, 'schema');
|
||||||
require('./lib/schema')(Knex, function() {
|
require('./lib/schema')(Knex, function() {
|
||||||
setTimeout(function() { ok(); }, 100);
|
ok();
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
throw new Error(err);
|
throw new Error(err);
|
||||||
}, type);
|
}, type);
|
||||||
@ -83,7 +83,7 @@ var handler = function(instance, section) {
|
|||||||
try {
|
try {
|
||||||
assert.deepEqual(checkData, data);
|
assert.deepEqual(checkData, data);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log([checkData, data]);
|
//console.log([checkData, data]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
item++;
|
item++;
|
||||||
|
|||||||
@ -15,7 +15,7 @@ module.exports = function(Knex, type) {
|
|||||||
var val = handler(type, 'schema');
|
var val = handler(type, 'schema');
|
||||||
require('./lib/schema')(Knex, val(ok, true), function(err) {
|
require('./lib/schema')(Knex, val(ok, true), function(err) {
|
||||||
throw new Error(err);
|
throw new Error(err);
|
||||||
});
|
}, 'String');
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Knex.Builder', function() {
|
describe('Knex.Builder', function() {
|
||||||
@ -82,7 +82,7 @@ var handler = function(instance, section) {
|
|||||||
try {
|
try {
|
||||||
assert.deepEqual(a, b);
|
assert.deepEqual(a, b);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log([a, b]);
|
//console.log([a, b]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
item++;
|
item++;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user