Skip to content

Commit

Permalink
release 0.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tgriesser committed Jun 4, 2014
1 parent 0d749fc commit 4bb6465
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 2,057 deletions.
93 changes: 53 additions & 40 deletions browser/knex.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ Knex.initialize = function(config) {
};

module.exports = Knex;

},{"./lib/dialects/maria":3,"./lib/dialects/mysql":6,"./lib/dialects/postgres":19,"./lib/dialects/sqlite3":32,"./lib/dialects/websql":44,"./lib/migrate/methods":49,"./lib/query/methods":55,"./lib/raw":56,"./lib/schema/methods":63,"./lib/utils":67,"events":71,"lodash":"K2RcUv"}],2:[function(_dereq_,module,exports){
// "Base Client"
// ------
Expand Down Expand Up @@ -314,25 +315,13 @@ Runner_MariaSQL.prototype._stream = Promise.method(function(sql, stream, options
runner.connection.query(sql.sql, sql.bindings)
.on('result', function(result) {
result
.on('row', function(row) { stream.write(row); })
.on('row', rowHandler(function(row) { stream.write(row); }))
.on('end', function(data) { resolver(data); });
})
.on('error', function(err) { rejecter(err); });
});
});

Runner_MariaSQL.prototype.parseType = function(value, type) {
switch (type) {
case 'DATETIME':
case 'TIMESTAMP':
return new Date(value);
case 'INTEGER':
return parseInt(value, 10);
default:
return value;
}
};

// Runs the query on the specified connection, providing the bindings
// and any other necessary prep work.
Runner_MariaSQL.prototype._query = Promise.method(function(obj) {
Expand All @@ -341,20 +330,11 @@ Runner_MariaSQL.prototype._query = Promise.method(function(obj) {
var connection = this.connection;
var tz = this.client.connectionSettings.timezone || 'local';
if (!sql) throw new Error('The query is empty');
var runner = this;
return new Promise(function(resolver, rejecter) {
var types, rows = [];
var rows = [];
var query = connection.query(SqlString.format(sql, obj.bindings, false, tz), []);
query.on('result', function(result) {
result.on('row', function(row, meta) {
if (!types) types = meta.types;
var keys = Object.keys(types);
for (var i = 0, l = keys.length; i < l; i++) {
var type = keys[i];
row[type] = runner.parseType(row[type], types[type]);
}
rows.push(row);
})
result.on('row', rowHandler(function(row) { rows.push(row); }))
.on('end', function(data) {
obj.response = [rows, data];
resolver(obj);
Expand Down Expand Up @@ -386,6 +366,31 @@ Runner_MariaSQL.prototype.processResponse = function(obj) {
return resp;
};

function parseType(value, type) {
switch (type) {
case 'DATETIME':
case 'TIMESTAMP':
return new Date(value);
case 'INTEGER':
return parseInt(value, 10);
default:
return value;
}
}

function rowHandler(callback) {
var types;
return function(row, meta) {
if (!types) types = meta.types;
var keys = Object.keys(types);
for (var i = 0, l = keys.length; i < l; i++) {
var type = keys[i];
row[type] = parseType(row[type], types[type]);
}
callback(row);
};
}

// Assign the newly extended `Runner` constructor to the client object.
client.Runner = Runner_MariaSQL;

Expand Down Expand Up @@ -1018,13 +1023,15 @@ TableCompiler_MySQL.prototype.unique = function(columns, indexName) {
};

// Compile a drop index command.
TableCompiler_MySQL.prototype.dropIndex = function(key) {
this.pushQuery('alter table ' + this.tableName() + ' drop index ' + key);
TableCompiler_MySQL.prototype.dropIndex = function(columns, indexName) {
indexName = indexName || this._indexCommand('index', this.tableNameRaw, columns);
this.pushQuery('alter table ' + this.tableName() + ' drop index ' + indexName);
};

// Compile a drop foreign key command.
TableCompiler_MySQL.prototype.dropForeign = function(key) {
this.pushQuery('alter table ' + this.tableName() + ' drop foreign key ' + key);
TableCompiler_MySQL.prototype.dropForeign = function(columns, indexName) {
indexName = indexName || this._indexCommand('foreign', this.tableNameRaw, columns);
this.pushQuery('alter table ' + this.tableName() + ' drop foreign key ' + indexName);
};

// Compile a drop primary key command.
Expand All @@ -1033,8 +1040,9 @@ TableCompiler_MySQL.prototype.dropPrimary = function() {
};

// Compile a drop unique key command.
TableCompiler_MySQL.prototype.dropUnique = function(key) {
this.pushQuery('alter table ' + this.tableName() + ' drop index ' + key);
TableCompiler_MySQL.prototype.dropUnique = function(column, indexName) {
indexName = indexName || this._indexCommand('unique', this.tableNameRaw, column);
this.pushQuery('alter table ' + this.tableName() + ' drop index ' + indexName);
};

// Compile a foreign key command.
Expand Down Expand Up @@ -1841,14 +1849,17 @@ TableCompiler_PG.prototype.index = function(columns, indexName) {
TableCompiler_PG.prototype.dropPrimary = function() {
this.pushQuery('alter table ' + this.tableName() + " drop constraint " + this.tableNameRaw + "_pkey");
};
TableCompiler_PG.prototype.dropIndex = function(index) {
this.pushQuery('drop index ' + index);
TableCompiler_PG.prototype.dropIndex = function(columns, indexName) {
indexName = indexName || this._indexCommand('index', this.tableNameRaw, columns);
this.pushQuery('drop index ' + indexName);
};
TableCompiler_PG.prototype.dropUnique = function(index) {
this.pushQuery('alter table ' + this.tableName() + ' drop constraint ' + index);
TableCompiler_PG.prototype.dropUnique = function(columns, indexName) {
indexName = indexName || this._indexCommand('unique', this.tableNameRaw, columns);
this.pushQuery('alter table ' + this.tableName() + ' drop constraint ' + indexName);
};
TableCompiler_PG.prototype.dropForeign = function(index) {
this.pushQuery('alter table ' + this.tableName() + ' drop constraint ' + index);
TableCompiler_PG.prototype.dropForeign = function(columns, indexName) {
indexName = indexName || this._indexCommand('foreign', this.tableNameRaw, columns);
this.pushQuery('alter table ' + this.tableName() + ' drop constraint ' + indexName);
};

client.TableBuilder = TableBuilder_PG;
Expand Down Expand Up @@ -2681,12 +2692,14 @@ TableCompiler_SQLite3.prototype.addColumns = function(columns) {
};

// Compile a drop unique key command.
TableCompiler_SQLite3.prototype.dropUnique = function(value) {
this.pushQuery('drop index ' + value);
TableCompiler_SQLite3.prototype.dropUnique = function(columns, indexName) {
indexName = indexName || this._indexCommand('unique', this.tableNameRaw, columns);
this.pushQuery('drop index ' + indexName);
};

TableCompiler_SQLite3.prototype.dropIndex = function(index) {
this.pushQuery('drop index ' + index);
TableCompiler_SQLite3.prototype.dropIndex = function(columns, indexName) {
indexName = indexName || this._indexCommand('index', this.tableNameRaw, columns);
this.pushQuery('drop index ' + indexName);
};

// Compile a unique key command.
Expand Down
11 changes: 7 additions & 4 deletions browser/websql.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ Knex.initialize = function(config) {
};

module.exports = Knex;

},{"./lib/dialects/websql":17,"./lib/migrate/methods":22,"./lib/query/methods":28,"./lib/raw":29,"./lib/schema/methods":36,"./lib/utils":40,"events":44,"lodash":"K2RcUv"}],2:[function(_dereq_,module,exports){
// "Base Client"
// ------
Expand Down Expand Up @@ -1085,12 +1086,14 @@ TableCompiler_SQLite3.prototype.addColumns = function(columns) {
};

// Compile a drop unique key command.
TableCompiler_SQLite3.prototype.dropUnique = function(value) {
this.pushQuery('drop index ' + value);
TableCompiler_SQLite3.prototype.dropUnique = function(columns, indexName) {
indexName = indexName || this._indexCommand('unique', this.tableNameRaw, columns);
this.pushQuery('drop index ' + indexName);
};

TableCompiler_SQLite3.prototype.dropIndex = function(index) {
this.pushQuery('drop index ' + index);
TableCompiler_SQLite3.prototype.dropIndex = function(columns, indexName) {
indexName = indexName || this._indexCommand('index', this.tableNameRaw, columns);
this.pushQuery('drop index ' + indexName);
};

// Compile a unique key command.
Expand Down
2,012 changes: 0 additions & 2,012 deletions docs/assets/behavior.js

This file was deleted.

1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2155,6 +2155,7 @@ <h2 id="changelog">Change Log</h2>

<ul>
<li>Major internal overhaul to clean up the various dialect code.</li>
<li>Improved unit test suite.</li>
<li>Support for the <a href="https://github.com/mscdex/node-mariasql">mariasql</a> driver.</li>
<li>More consistent use of raw query bindings throughout the library.</li>
<li>Queries are more composable, may be injected in various points throughout the builder.</li>
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
"scripts": {
"build": "gulp build",
"test": "mocha -b --check-leaks -R spec test/index.js",
"jshint": "jshint knex.js lib/*"
"jshint": "jshint knex.js lib/*",
"release:patch": "npm run jshint && npm test && gulp build && gulp release --type patch",
"release:minor": "npm run jshint && npm test && gulp build && gulp release --type minor"
},
"bin": {
"knex": "./node_modules/knex-cli/bin/knex-cli.js"
Expand Down

0 comments on commit 4bb6465

Please sign in to comment.