most of the functionality is now restored

This commit is contained in:
Tim Griesser 2013-09-12 02:09:29 -04:00
parent dc312f322b
commit 847f926c38
5 changed files with 29 additions and 24 deletions

View File

@ -15,7 +15,7 @@ var sqlite3 = require('sqlite3');
var SQLite3Base = require('../base/sqlite3');
var ServerBase = require('./base').ServerBase;
var Builder = require('../../lib/builder').Builder;
var transaction = require('../../lib/transaction').transaction;
var Transaction = require('../../lib/transaction').Transaction;
var SchemaInterface = require('../../lib/schemainterface').SchemaInterface;
var Helpers = require('../../lib/helpers').Helpers;
@ -29,6 +29,9 @@ var SQLite3Client = exports.Client = ServerBase.extend({
initialize: function() {},
runQuery: function(connection, sql, bindings, builder) {
if (sql === '__rename_column__') {
return this.ddl(connection, sql, bindings, builder);
}
var method = (builder.type === 'insert' ||
builder.type === 'update' || builder.type === 'delete') ? 'run' : 'all';
// Call the querystring and then release the client
@ -41,22 +44,23 @@ var SQLite3Client = exports.Client = ServerBase.extend({
return dfd.promise;
},
// Prepare the query...
prepareQuery: function(connection, sql) {
return sql;
if (sql === '__rename_column__') {
return transaction.call(builder, function(trx) {
instance.alterSchema.call(instance, builder, trx);
});
}
},
poolDefaults: {
max: 1,
min: 1,
destroy: function(client) { client.close(); }
},
ddl: function(connection, sql, bindings, builder) {
var client = this;
return nodefn.call(connection.run.bind(connection), 'begin transaction;').then(function() {
var transaction = new Transaction({client: client});
var containerObj = transaction.getContainerObject(connection);
return transaction.initiateDeferred(function(trx) {
client.alterSchema.call(client, builder, trx);
})(containerObj);
});
},
getRawConnection: function() {
var dfd = when.defer();
var db = new sqlite3.Database(this.connectionSettings.filename, function(err) {
@ -92,7 +96,6 @@ var SQLite3Client = exports.Client = ServerBase.extend({
// This needs to be refactored... badly.
alterSchema: function(builder, trx) {
var instance = this;
var connection = trx.connection;
var currentCol, command;
@ -120,7 +123,7 @@ var SQLite3Client = exports.Client = ServerBase.extend({
nodefn.call(connection.all.bind(connection), 'SELECT * FROM "__migrate__' + sql.name + '"'),
]);
}).spread(function(createTable, selected) {
var qb = new Builder(instance).transacting(trx);
var qb = new Builder(builder.knex).transacting(trx);
qb.table = builder.table;
return when.all([
qb.insert(_.map(selected, function(row) {

View File

@ -18,6 +18,14 @@ define(function(require, exports) {
// Check whether the query is able to be debugged.
isDebugging: false,
// Creates a new instance of the current `Builder` or `SchemaBuilder`,
// with the correct current `knex` instance.
instance: function() {
var builder = new this.constructor(this.knex);
builder.table = this.table;
return builder;
},
// Sets the flag, so that when this object is passed into the
// client adapter, we know to `log` the query.
debug: function() {
@ -105,7 +113,7 @@ define(function(require, exports) {
var cleaned = [];
for (var i = 0, l = bindings.length; i < l; i++) {
// if (bindings[i] == void 0) continue;
if (bindings[i]._source !== 'Raw') {
if (!bindings[i] || bindings[i]._source !== 'Raw') {
cleaned.push(bindings[i]);
} else {
push.apply(cleaned, bindings[i].bindings);

View File

@ -32,12 +32,6 @@ define(function(require, exports) {
}, this.instance(), this);
},
instance: function() {
var builder = new SchemaBuilder(this.knex);
builder.table = this.table;
return builder;
},
// A callback from the table building `Knex.schemaBuilder` calls.
callback: function(callback) {
if (callback) callback.call(this, this);

View File

@ -16,8 +16,8 @@ define(function(require, exports) {
// Passed a `container` function, this method runs the current
// transaction, returning a promise.
run: function(container) {
return this.client.startTransaction()
run: function(container, connection) {
return this.client.startTransaction(connection)
.then(this.getContainerObject)
.then(this.initiateDeferred(container));
},

View File

@ -43,19 +43,19 @@ describe('Integration Tests', function() {
before(function() {
var context = this;
SchemaBuilder.prototype.logMe = Builder.prototype.logMe = function(logWhat) {
this.isLogging = logWhat || true;
return this;
};
SchemaBuilder.prototype.then = Builder.prototype.then = function() {
if (this.isLogging) {
// If we're not only logging the sql for this query...
if (this.isLogging !== 'result') {
console.log(this.toString());
}
}