mirror of
https://github.com/knex/knex.git
synced 2026-01-03 18:48:37 +00:00
minor cleanup, 0.1.4
This commit is contained in:
parent
d0ab01a5da
commit
837ddd0118
@ -1,4 +1,3 @@
|
||||
var When = require('when');
|
||||
var nodefn = require('when/node/function');
|
||||
var _ = require('underscore');
|
||||
|
||||
@ -81,20 +80,20 @@ exports.protoProps = {
|
||||
exports.grammar = {};
|
||||
|
||||
exports.schemaGrammar = {
|
||||
|
||||
|
||||
// Compile a create table command.
|
||||
compileCreateTable: function(blueprint, command) {
|
||||
compileCreateTable: function(blueprint) {
|
||||
var columns = this.getColumns(blueprint).join(', ');
|
||||
return 'create table ' + this.wrapTable(blueprint) + ' (' + columns + ')';
|
||||
},
|
||||
|
||||
// Compile a drop table command.
|
||||
compileDropTable: function(blueprint, command) {
|
||||
compileDropTable: function(blueprint) {
|
||||
return 'drop table ' + this.wrapTable(blueprint);
|
||||
},
|
||||
|
||||
// Compile a drop table (if exists) command.
|
||||
compileDropTableIfExists: function(blueprint, command) {
|
||||
compileDropTableIfExists: function(blueprint) {
|
||||
return 'drop table if exists ' + this.wrapTable(blueprint);
|
||||
},
|
||||
|
||||
@ -109,17 +108,17 @@ exports.schemaGrammar = {
|
||||
},
|
||||
|
||||
// Create the column definition for a time type.
|
||||
typeTime: function(column) {
|
||||
typeTime: function() {
|
||||
return 'time';
|
||||
},
|
||||
|
||||
// Create the column definition for a date type.
|
||||
typeDate: function(column) {
|
||||
typeDate: function() {
|
||||
return 'date';
|
||||
},
|
||||
|
||||
// Create the column definition for a binary type.
|
||||
typeBinary: function(column) {
|
||||
typeBinary: function() {
|
||||
return 'blob';
|
||||
},
|
||||
|
||||
|
||||
@ -107,7 +107,7 @@ MysqlClient.schemaGrammar = _.extend({}, base.schemaGrammar, MysqlClient.grammar
|
||||
},
|
||||
|
||||
// Compile an add command.
|
||||
compileAdd: function(blueprint, command) {
|
||||
compileAdd: function(blueprint) {
|
||||
var columns = this.prefixArray('add', this.getColumns(blueprint));
|
||||
return 'alter table ' + this.wrapTable(blueprint) + ' ' + columns.join(', ');
|
||||
},
|
||||
@ -142,7 +142,7 @@ MysqlClient.schemaGrammar = _.extend({}, base.schemaGrammar, MysqlClient.grammar
|
||||
},
|
||||
|
||||
// Compile a drop primary key command.
|
||||
compileDropPrimary: function(blueprint, command) {
|
||||
compileDropPrimary: function(blueprint) {
|
||||
return 'alter table ' + this.wrapTable(blueprint) + ' drop primary key';
|
||||
},
|
||||
|
||||
@ -201,7 +201,7 @@ MysqlClient.schemaGrammar = _.extend({}, base.schemaGrammar, MysqlClient.grammar
|
||||
},
|
||||
|
||||
// Create the column definition for a boolean type.
|
||||
typeBoolean: function(column) {
|
||||
typeBoolean: function() {
|
||||
return 'tinyint(1)';
|
||||
},
|
||||
|
||||
@ -211,12 +211,12 @@ MysqlClient.schemaGrammar = _.extend({}, base.schemaGrammar, MysqlClient.grammar
|
||||
},
|
||||
|
||||
// Create the column definition for a date-time type.
|
||||
typeDateTime: function(column) {
|
||||
typeDateTime: function() {
|
||||
return 'datetime';
|
||||
},
|
||||
|
||||
// Create the column definition for a timestamp type.
|
||||
typeTimestamp: function(column) {
|
||||
typeTimestamp: function() {
|
||||
return 'timestamp default 0';
|
||||
},
|
||||
|
||||
|
||||
@ -28,7 +28,7 @@ _.extend(PostgresClient.prototype, base.protoProps, {
|
||||
questionCount++;
|
||||
return '$' + questionCount;
|
||||
});
|
||||
|
||||
|
||||
// If we have a debug flag set, console.log the query.
|
||||
if (debug) base.debug(builder, conn);
|
||||
|
||||
@ -113,7 +113,7 @@ PostgresClient.schemaGrammar = _.extend({}, base.schemaGrammar, PostgresClient.g
|
||||
},
|
||||
|
||||
// Compile a create table command.
|
||||
compileAdd: function(blueprint, command) {
|
||||
compileAdd: function(blueprint) {
|
||||
var table = this.wrapTable(blueprint);
|
||||
var columns = this.prefixArray('add column', this.getColumns(blueprint));
|
||||
return 'alter table ' + table + ' ' + columns.join(', ');
|
||||
@ -141,12 +141,12 @@ PostgresClient.schemaGrammar = _.extend({}, base.schemaGrammar, PostgresClient.g
|
||||
// Compile a drop column command.
|
||||
compileDropColumn: function(blueprint, command) {
|
||||
var columns = this.prefixArray('drop column', this.wrapArray(command.columns));
|
||||
table = this.wrapTable(blueprint);
|
||||
var table = this.wrapTable(blueprint);
|
||||
return 'alter table ' + table + ' ' + columns.join(', ');
|
||||
},
|
||||
|
||||
// Compile a drop primary key command.
|
||||
compileDropPrimary: function(blueprint, command) {
|
||||
compileDropPrimary: function(blueprint) {
|
||||
var table = blueprint.getTable();
|
||||
return 'alter table ' + this.wrapTable(blueprint) + " drop constraint " + table + "_pkey";
|
||||
},
|
||||
@ -174,7 +174,7 @@ PostgresClient.schemaGrammar = _.extend({}, base.schemaGrammar, PostgresClient.g
|
||||
},
|
||||
|
||||
// Create the column definition for a text type.
|
||||
typeText: function(column) {
|
||||
typeText: function() {
|
||||
return 'text';
|
||||
},
|
||||
|
||||
@ -184,12 +184,12 @@ PostgresClient.schemaGrammar = _.extend({}, base.schemaGrammar, PostgresClient.g
|
||||
},
|
||||
|
||||
// Create the column definition for a tiny integer type.
|
||||
typeTinyInteger: function(column) {
|
||||
typeTinyInteger: function() {
|
||||
return 'smallint';
|
||||
},
|
||||
|
||||
// Create the column definition for a float type.
|
||||
typeFloat: function(column) {
|
||||
typeFloat: function() {
|
||||
return 'real';
|
||||
},
|
||||
|
||||
@ -199,7 +199,7 @@ PostgresClient.schemaGrammar = _.extend({}, base.schemaGrammar, PostgresClient.g
|
||||
},
|
||||
|
||||
// Create the column definition for a boolean type.
|
||||
typeBoolean: function(column) {
|
||||
typeBoolean: function() {
|
||||
return 'boolean';
|
||||
},
|
||||
|
||||
@ -209,12 +209,12 @@ PostgresClient.schemaGrammar = _.extend({}, base.schemaGrammar, PostgresClient.g
|
||||
},
|
||||
|
||||
// Create the column definition for a date-time type.
|
||||
typeDateTime: function(column) {
|
||||
typeDateTime: function() {
|
||||
return 'timestamp';
|
||||
},
|
||||
|
||||
// Create the column definition for a timestamp type.
|
||||
typeTimestamp: function(column) {
|
||||
typeTimestamp: function() {
|
||||
return 'timestamp';
|
||||
},
|
||||
|
||||
@ -224,7 +224,7 @@ PostgresClient.schemaGrammar = _.extend({}, base.schemaGrammar, PostgresClient.g
|
||||
},
|
||||
|
||||
// Create the column definition for a binary type.
|
||||
typeBinary: function(column) {
|
||||
typeBinary: function() {
|
||||
return 'bytea';
|
||||
},
|
||||
|
||||
|
||||
@ -118,8 +118,6 @@ Sqlite3Client.grammar = {
|
||||
compileInsert: function(qb) {
|
||||
var values = qb.values;
|
||||
var table = this.wrapTable(qb.table);
|
||||
var parameters = this.parameterize(values[0]);
|
||||
var paramBlocks = [];
|
||||
|
||||
// If there is only one record being inserted, we will just use the usual query
|
||||
// grammar insert builder because no special syntax is needed for the single
|
||||
@ -127,7 +125,7 @@ Sqlite3Client.grammar = {
|
||||
if (values.length === 1) {
|
||||
return require('../knex').Grammar.compileInsert.call(this, qb);
|
||||
}
|
||||
|
||||
|
||||
var keys = _.keys(values[0]).sort();
|
||||
var names = this.columnize(keys);
|
||||
var columns = [];
|
||||
@ -161,20 +159,20 @@ Sqlite3Client.grammar = {
|
||||
|
||||
// Grammar for the schema builder.
|
||||
Sqlite3Client.schemaGrammar = _.extend({}, base.schemaGrammar, Sqlite3Client.grammar, {
|
||||
|
||||
|
||||
// The possible column modifiers.
|
||||
modifiers: ['Nullable', 'Default', 'Increment'],
|
||||
|
||||
|
||||
// Compile the query to determine if a table exists.
|
||||
compileTableExists: function() {
|
||||
return "select * from sqlite_master where type = 'table' and name = ?";
|
||||
},
|
||||
|
||||
// Compile a create table command.
|
||||
compileCreateTable: function(blueprint, command) {
|
||||
compileCreateTable: function(blueprint) {
|
||||
var columns = this.getColumns(blueprint).join(', ');
|
||||
var sql = 'create table ' + this.wrapTable(blueprint) + ' (' + columns;
|
||||
|
||||
|
||||
// SQLite forces primary keys to be added when the table is initially created
|
||||
// so we will need to check for a primary key commands and add the columns
|
||||
// to the table's declaration here so they can be created on the tables.
|
||||
@ -201,13 +199,13 @@ Sqlite3Client.schemaGrammar = _.extend({}, base.schemaGrammar, Sqlite3Client.gra
|
||||
}
|
||||
return sql;
|
||||
},
|
||||
|
||||
|
||||
// Get the primary key command if it exists on the blueprint.
|
||||
getCommandByName: function(blueprint, name) {
|
||||
var commands = this.getCommandsByName(blueprint, name);
|
||||
if (commands.length > 0) return commands[0];
|
||||
},
|
||||
|
||||
|
||||
// Get all of the commands with a given name.
|
||||
getCommandsByName: function(blueprint, name) {
|
||||
return _.where(blueprint.commands, function(value) { return value.name == name; });
|
||||
@ -223,7 +221,7 @@ Sqlite3Client.schemaGrammar = _.extend({}, base.schemaGrammar, Sqlite3Client.gra
|
||||
},
|
||||
|
||||
// Compile alter table commands for adding columns
|
||||
compileAdd: function(blueprint, command) {
|
||||
compileAdd: function(blueprint) {
|
||||
var table = this.wrapTable(blueprint);
|
||||
var columns = this.prefixArray('add column', this.getColumns(blueprint));
|
||||
var statements = [];
|
||||
@ -239,84 +237,84 @@ Sqlite3Client.schemaGrammar = _.extend({}, base.schemaGrammar, Sqlite3Client.gra
|
||||
var table = this.wrapTable(blueprint);
|
||||
return 'create unique index ' + command.index + ' on ' + table + ' (' + columns + ')';
|
||||
},
|
||||
|
||||
|
||||
// Compile a plain index key command.
|
||||
compileIndex: function(blueprint, command) {
|
||||
var columns = this.columnize(command.columns);
|
||||
var table = this.wrapTable(blueprint);
|
||||
return 'create index ' + command.index + ' on ' + table + ' (' + columns + ')';
|
||||
},
|
||||
|
||||
|
||||
// Compile a foreign key command.
|
||||
compileForeign: function(blueprint, command) {
|
||||
compileForeign: function() {
|
||||
// Handled on table creation...
|
||||
},
|
||||
|
||||
|
||||
// Compile a drop column command.
|
||||
compileDropColumn: function(blueprint, command) {
|
||||
compileDropColumn: function() {
|
||||
throw new Error("Drop column not supported for SQLite.");
|
||||
},
|
||||
|
||||
|
||||
// Compile a drop unique key command.
|
||||
compileDropUnique: function(blueprint, command) {
|
||||
return 'drop index ' + command.index;
|
||||
},
|
||||
|
||||
|
||||
// Compile a rename table command.
|
||||
compileRenameTable: function(blueprint, command) {
|
||||
return 'alter table ' + this.wrapTable(blueprint) + ' rename to ' + this.wrapTable(command.to);
|
||||
},
|
||||
|
||||
|
||||
// Create the column definition for a string type.
|
||||
typeString: function(column) {
|
||||
typeString: function() {
|
||||
return 'varchar';
|
||||
},
|
||||
|
||||
|
||||
// Create the column definition for a text type.
|
||||
typeText: function(column) {
|
||||
typeText: function() {
|
||||
return 'text';
|
||||
},
|
||||
|
||||
|
||||
// Create the column definition for a integer type.
|
||||
typeInteger: function(column) {
|
||||
typeInteger: function() {
|
||||
return 'integer';
|
||||
},
|
||||
|
||||
|
||||
// Create the column definition for a float type.
|
||||
typeFloat: function(column) {
|
||||
typeFloat: function() {
|
||||
return 'float';
|
||||
},
|
||||
|
||||
|
||||
// Create the column definition for a decimal type.
|
||||
typeDecimal: function(column) {
|
||||
typeDecimal: function() {
|
||||
return 'float';
|
||||
},
|
||||
|
||||
|
||||
// Create the column definition for a boolean type.
|
||||
typeBoolean: function(column) {
|
||||
typeBoolean: function() {
|
||||
return 'tinyint';
|
||||
},
|
||||
|
||||
// Create the column definition for a enum type.
|
||||
typeEnum: function(column) {
|
||||
typeEnum: function() {
|
||||
return 'varchar';
|
||||
},
|
||||
|
||||
|
||||
// Create the column definition for a date-time type.
|
||||
typeDateTime: function(column) {
|
||||
typeDateTime: function() {
|
||||
return 'datetime';
|
||||
},
|
||||
|
||||
|
||||
// Create the column definition for a timestamp type.
|
||||
typeTimestamp: function(column) {
|
||||
typeTimestamp: function() {
|
||||
return 'datetime';
|
||||
},
|
||||
|
||||
|
||||
// Get the SQL for a nullable column modifier.
|
||||
modifyNullable: function(blueprint) {
|
||||
modifyNullable: function() {
|
||||
return ' null';
|
||||
},
|
||||
|
||||
|
||||
// Get the SQL for an auto-increment column modifier.
|
||||
modifyIncrement: function(blueprint, column) {
|
||||
if (column.type == 'integer' && column.autoIncrement) {
|
||||
|
||||
110
docs/knex.html
110
docs/knex.html
@ -27,7 +27,7 @@
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-1">¶</a>
|
||||
</div>
|
||||
<pre><code>Knex.js 0.1.3
|
||||
<pre><code>Knex.js 0.1.4
|
||||
|
||||
(c) 2013 Tim Griesser
|
||||
Knex may be freely distributed under the MIT license.
|
||||
@ -91,7 +91,7 @@ http://knexjs.org</code></pre>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> Knex.VERSION = <span class="string">'0.1.3'</span>;</pre></div></div>
|
||||
<div class="content"><div class='highlight'><pre> Knex.VERSION = <span class="string">'0.1.4'</span>;</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
@ -169,7 +169,7 @@ if called more than once.</p>
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-8">¶</a>
|
||||
</div>
|
||||
<p>Returns an array of query strings filled out with the
|
||||
<p>Returns an array of query strings filled out with the
|
||||
correct values based on bindings, etc. Useful for debugging.</p>
|
||||
|
||||
</div>
|
||||
@ -442,7 +442,7 @@ the empties, and returning a generated query string.</p>
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-21">¶</a>
|
||||
</div>
|
||||
<p>Compiles all each of the <code>join</code> clauses on the query,
|
||||
<p>Compiles all each of the <code>join</code> clauses on the query,
|
||||
including any nested join queries.</p>
|
||||
|
||||
</div>
|
||||
@ -816,7 +816,7 @@ inserts using a single query statement.</p>
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-40">¶</a>
|
||||
</div>
|
||||
<p>If there are any "where" clauses, we need to omit
|
||||
<p>If there are any "where" clauses, we need to omit
|
||||
any bindings that may have been associated with them.</p>
|
||||
|
||||
</div>
|
||||
@ -947,7 +947,7 @@ query to be used for <code>insert</code> and <code>update</code> without issue.<
|
||||
|
||||
wrapTable: <span class="keyword">function</span>(table) {
|
||||
<span class="keyword">if</span> (table <span class="keyword">instanceof</span> Raw) <span class="keyword">return</span> table.value;
|
||||
<span class="keyword">return</span> <span class="keyword">this</span>.wrapValue(table);
|
||||
<span class="keyword">return</span> <span class="keyword">this</span>.wrap(table);
|
||||
},
|
||||
|
||||
columnize: <span class="keyword">function</span>(columns) {
|
||||
@ -1006,7 +1006,7 @@ for the advanced query statements.</p>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="keyword">if</span> (table) {
|
||||
<span class="keyword">if</span> (_.isString(table)) {
|
||||
<span class="keyword">this</span>.table = table;
|
||||
<span class="keyword">this</span>.table = table;
|
||||
} <span class="keyword">else</span> {
|
||||
<span class="keyword">this</span>.client = table.client;
|
||||
<span class="keyword">this</span>.grammar = table.grammar;
|
||||
@ -1224,7 +1224,7 @@ with an anonymous function as the second argument.</p>
|
||||
</div>
|
||||
<p>The where function can be used in several ways:
|
||||
The most basic is <code>where(key, value)</code>, which expands to
|
||||
where key = value. </p>
|
||||
where key = value.</p>
|
||||
|
||||
</div>
|
||||
|
||||
@ -1875,7 +1875,7 @@ where key = value. </p>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> select: <span class="keyword">function</span>(columns) {
|
||||
<span class="keyword">if</span> (columns) {
|
||||
push.apply(<span class="keyword">this</span>.columns, _.isArray(columns) ? columns : _.toArray(arguments));
|
||||
push.apply(<span class="keyword">this</span>.columns, _.isArray(columns) ? columns : _.toArray(arguments));
|
||||
}
|
||||
<span class="keyword">return</span> <span class="keyword">this</span>._setType(<span class="string">'select'</span>);
|
||||
},</pre></div></div>
|
||||
@ -1948,7 +1948,7 @@ where key = value. </p>
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-95">¶</a>
|
||||
</div>
|
||||
<p>Executes a delete statement on the query; </p>
|
||||
<p>Executes a delete statement on the query;</p>
|
||||
|
||||
</div>
|
||||
|
||||
@ -2617,7 +2617,7 @@ SchemaBuilder instance methods</p>
|
||||
<div class="content"><div class='highlight'><pre> <span class="keyword">for</span> (<span class="keyword">var</span> i = <span class="number">0</span>, l = <span class="keyword">this</span>.columns.length; i < l; i++) {
|
||||
<span class="keyword">var</span> column = <span class="keyword">this</span>.columns[i];
|
||||
<span class="keyword">var</span> indices = [<span class="string">'primary'</span>, <span class="string">'unique'</span>, <span class="string">'index'</span>];
|
||||
|
||||
|
||||
continueIndex:
|
||||
<span class="keyword">for</span> (<span class="keyword">var</span> i2 = <span class="number">0</span>, l2 = indices.length; i2 < l2; i2++) {
|
||||
<span class="keyword">var</span> index = indices[i2];
|
||||
@ -3382,11 +3382,17 @@ index type, such as primary or index, which makes the index unique.</p>
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-172">¶</a>
|
||||
</div>
|
||||
<p>Sets the default value for a column.</p>
|
||||
<p>Sets the default value for a column.
|
||||
For <code>boolean</code> columns, we'll permit 'false'
|
||||
to be used as default values.</p>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> defaultTo: <span class="keyword">function</span>(value) {
|
||||
<span class="keyword">if</span> (<span class="keyword">this</span>.type === <span class="string">'boolean'</span>) {
|
||||
<span class="keyword">if</span> (value === <span class="string">'false'</span>) value = <span class="number">0</span>;
|
||||
value = (value ? <span class="number">1</span> : <span class="number">0</span>);
|
||||
}
|
||||
<span class="keyword">this</span>.defaultValue = value;
|
||||
<span class="keyword">return</span> <span class="keyword">this</span>;
|
||||
},</pre></div></div>
|
||||
@ -3814,8 +3820,8 @@ is an instanceof Raw, and if it is, use the supplied value.</p>
|
||||
</div>
|
||||
|
||||
<div class="content"><div class='highlight'><pre> <span class="keyword">var</span> sortObject = <span class="keyword">function</span>(obj) {
|
||||
<span class="keyword">return</span> _.sortBy(_.pairs(obj), <span class="keyword">function</span>(a) {
|
||||
<span class="keyword">return</span> a[<span class="number">0</span>];
|
||||
<span class="keyword">return</span> _.sortBy(_.pairs(obj), <span class="keyword">function</span>(a) {
|
||||
<span class="keyword">return</span> a[<span class="number">0</span>];
|
||||
});
|
||||
};</pre></div></div>
|
||||
|
||||
@ -3863,22 +3869,10 @@ is an instanceof Raw, and if it is, use the supplied value.</p>
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-197">¶</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-198">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-198">¶</a>
|
||||
</div>
|
||||
<p>Takes a hash of options to initialize the database
|
||||
connection. The <code>client</code> is required to choose which client
|
||||
path above is loaded, or to specify a custom path to a client.
|
||||
Other options, such as <code>connection</code> or <code>pool</code> are passed
|
||||
Other options, such as <code>connection</code> or <code>pool</code> are passed
|
||||
into <code>client.initialize</code>.</p>
|
||||
|
||||
</div>
|
||||
@ -3889,11 +3883,11 @@ into <code>client.initialize</code>.</p>
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-199">
|
||||
<li id="section-198">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-199">¶</a>
|
||||
<a class="pilcrow" href="#section-198">¶</a>
|
||||
</div>
|
||||
<p>A name for the connection isn't required in
|
||||
cases where there is only a single connection.</p>
|
||||
@ -3908,11 +3902,11 @@ cases where there is only a single connection.</p>
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-200">
|
||||
<li id="section-199">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-200">¶</a>
|
||||
<a class="pilcrow" href="#section-199">¶</a>
|
||||
</div>
|
||||
<p>Don't try to initialize the same <code>name</code> twice... If necessary,
|
||||
delete the instance from <code>Knex.Instances</code>.</p>
|
||||
@ -3924,17 +3918,17 @@ delete the instance from <code>Knex.Instances</code>.</p>
|
||||
}
|
||||
|
||||
client = options.client;
|
||||
|
||||
|
||||
<span class="keyword">if</span> (!client) <span class="keyword">throw</span> <span class="keyword">new</span> Error(<span class="string">'The client is required to use Knex.'</span>);</pre></div></div>
|
||||
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-201">
|
||||
<li id="section-200">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-201">¶</a>
|
||||
<a class="pilcrow" href="#section-200">¶</a>
|
||||
</div>
|
||||
<p>Checks if this is a default client. If it's not,
|
||||
that means it's a custom lib, set the object to the client.</p>
|
||||
@ -3951,11 +3945,11 @@ that means it's a custom lib, set the object to the client.</p>
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-202">
|
||||
<li id="section-201">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-202">¶</a>
|
||||
<a class="pilcrow" href="#section-201">¶</a>
|
||||
</div>
|
||||
<p>Creates a new instance of the db client, passing the name and options.</p>
|
||||
|
||||
@ -3966,11 +3960,11 @@ that means it's a custom lib, set the object to the client.</p>
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-203">
|
||||
<li id="section-202">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-203">¶</a>
|
||||
<a class="pilcrow" href="#section-202">¶</a>
|
||||
</div>
|
||||
<p>Setup the grammars specific to the client.</p>
|
||||
|
||||
@ -3982,11 +3976,11 @@ that means it's a custom lib, set the object to the client.</p>
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-204">
|
||||
<li id="section-203">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-204">¶</a>
|
||||
<a class="pilcrow" href="#section-203">¶</a>
|
||||
</div>
|
||||
<p>If this is named "default" then we're setting this on the Knex</p>
|
||||
|
||||
@ -4002,11 +3996,11 @@ that means it's a custom lib, set the object to the client.</p>
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-205">
|
||||
<li id="section-204">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-205">¶</a>
|
||||
<a class="pilcrow" href="#section-204">¶</a>
|
||||
</div>
|
||||
<p>Inherit static properties, without any that don't apply except
|
||||
on the "root" <code>Knex</code>.</p>
|
||||
@ -4018,11 +4012,11 @@ on the "root" <code>Knex</code>.</p>
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-206">
|
||||
<li id="section-205">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-206">¶</a>
|
||||
<a class="pilcrow" href="#section-205">¶</a>
|
||||
</div>
|
||||
<p>Initialize the schema builder methods.</p>
|
||||
|
||||
@ -4037,11 +4031,11 @@ on the "root" <code>Knex</code>.</p>
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-207">
|
||||
<li id="section-206">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-207">¶</a>
|
||||
<a class="pilcrow" href="#section-206">¶</a>
|
||||
</div>
|
||||
<p>Specifically set the client on the current target.</p>
|
||||
|
||||
@ -4053,11 +4047,11 @@ on the "root" <code>Knex</code>.</p>
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-208">
|
||||
<li id="section-207">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-208">¶</a>
|
||||
<a class="pilcrow" href="#section-207">¶</a>
|
||||
</div>
|
||||
<p>Setup the transacting function properly for this connection.</p>
|
||||
|
||||
@ -4070,11 +4064,11 @@ on the "root" <code>Knex</code>.</p>
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-209">
|
||||
<li id="section-208">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-209">¶</a>
|
||||
<a class="pilcrow" href="#section-208">¶</a>
|
||||
</div>
|
||||
<p>Executes a Raw query.</p>
|
||||
|
||||
@ -4089,11 +4083,11 @@ on the "root" <code>Knex</code>.</p>
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-210">
|
||||
<li id="section-209">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-210">¶</a>
|
||||
<a class="pilcrow" href="#section-209">¶</a>
|
||||
</div>
|
||||
<p>Add this instance to the global <code>Knex</code> instances, and return.</p>
|
||||
|
||||
@ -4107,11 +4101,11 @@ on the "root" <code>Knex</code>.</p>
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-211">
|
||||
<li id="section-210">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-211">¶</a>
|
||||
<a class="pilcrow" href="#section-210">¶</a>
|
||||
</div>
|
||||
<p>Default client paths, located in the <code>./clients</code> directory.</p>
|
||||
|
||||
@ -4128,11 +4122,11 @@ on the "root" <code>Knex</code>.</p>
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-212">
|
||||
<li id="section-211">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-212">¶</a>
|
||||
<a class="pilcrow" href="#section-211">¶</a>
|
||||
</div>
|
||||
<p>Named instances of Knex, presumably with different database
|
||||
connections, the main instance being named "main"...</p>
|
||||
@ -4144,11 +4138,11 @@ connections, the main instance being named "main"...</p>
|
||||
</li>
|
||||
|
||||
|
||||
<li id="section-213">
|
||||
<li id="section-212">
|
||||
<div class="annotation">
|
||||
|
||||
<div class="pilwrap ">
|
||||
<a class="pilcrow" href="#section-213">¶</a>
|
||||
<a class="pilcrow" href="#section-212">¶</a>
|
||||
</div>
|
||||
<p>Export the Knex module</p>
|
||||
|
||||
|
||||
50
knex.js
50
knex.js
@ -1,4 +1,4 @@
|
||||
// Knex.js 0.1.3
|
||||
// Knex.js 0.1.4
|
||||
//
|
||||
// (c) 2013 Tim Griesser
|
||||
// Knex may be freely distributed under the MIT license.
|
||||
@ -7,7 +7,7 @@
|
||||
(function() {
|
||||
|
||||
"use strict";
|
||||
|
||||
|
||||
// Required dependencies.
|
||||
var _ = require('underscore');
|
||||
var When = require('when');
|
||||
@ -23,7 +23,7 @@
|
||||
};
|
||||
|
||||
// Keep in sync with package.json
|
||||
Knex.VERSION = '0.1.3';
|
||||
Knex.VERSION = '0.1.4';
|
||||
|
||||
// Methods common to both the `Grammar` and `SchemaGrammar` interfaces,
|
||||
// used to generate the sql in one form or another.
|
||||
@ -56,7 +56,7 @@
|
||||
return this._promise.then(onFulfilled, onRejected);
|
||||
},
|
||||
|
||||
// Returns an array of query strings filled out with the
|
||||
// Returns an array of query strings filled out with the
|
||||
// correct values based on bindings, etc. Useful for debugging.
|
||||
toString: function() {
|
||||
this.type || (this.type = 'select');
|
||||
@ -175,7 +175,7 @@
|
||||
return 'from ' + this.wrapTable(table);
|
||||
},
|
||||
|
||||
// Compiles all each of the `join` clauses on the query,
|
||||
// Compiles all each of the `join` clauses on the query,
|
||||
// including any nested join queries.
|
||||
compileJoins: function(qb, joins) {
|
||||
var sql = [];
|
||||
@ -321,7 +321,7 @@
|
||||
var parameters = this.parameterize(_.values(values[0]));
|
||||
var paramBlocks = [];
|
||||
|
||||
// If there are any "where" clauses, we need to omit
|
||||
// If there are any "where" clauses, we need to omit
|
||||
// any bindings that may have been associated with them.
|
||||
if (qb.wheres.length > 0) this._clearWhereBindings(qb);
|
||||
|
||||
@ -420,12 +420,12 @@
|
||||
// Knex.Builder
|
||||
// -------
|
||||
var Builder = Knex.Builder = function(table) {
|
||||
|
||||
|
||||
// We use this logic to create sub-builders
|
||||
// for the advanced query statements.
|
||||
if (table) {
|
||||
if (_.isString(table)) {
|
||||
this.table = table;
|
||||
this.table = table;
|
||||
} else {
|
||||
this.client = table.client;
|
||||
this.grammar = table.grammar;
|
||||
@ -526,7 +526,7 @@
|
||||
|
||||
// The where function can be used in several ways:
|
||||
// The most basic is `where(key, value)`, which expands to
|
||||
// where key = value.
|
||||
// where key = value.
|
||||
where: function(column, operator, value, bool) {
|
||||
bool || (bool = 'and');
|
||||
if (_.isFunction(column)) {
|
||||
@ -733,7 +733,7 @@
|
||||
this.isLimit = value;
|
||||
return this;
|
||||
},
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
// Retrieve the "count" result of the query.
|
||||
@ -769,7 +769,7 @@
|
||||
// Sets the values for a `select` query.
|
||||
select: function(columns) {
|
||||
if (columns) {
|
||||
push.apply(this.columns, _.isArray(columns) ? columns : _.toArray(arguments));
|
||||
push.apply(this.columns, _.isArray(columns) ? columns : _.toArray(arguments));
|
||||
}
|
||||
return this._setType('select');
|
||||
},
|
||||
@ -797,7 +797,7 @@
|
||||
return this._setType('delete');
|
||||
},
|
||||
|
||||
// Executes a delete statement on the query;
|
||||
// Executes a delete statement on the query;
|
||||
del: function() {
|
||||
return this._setType('delete');
|
||||
},
|
||||
@ -880,7 +880,7 @@
|
||||
sql[column] = new Raw('' + this.grammar.wrap(column) + ' ' + (symbol || '+') + ' ' + amount);
|
||||
return this.update(sql);
|
||||
},
|
||||
|
||||
|
||||
// Helper for compiling any `union` queries.
|
||||
_union: function(callback, bool) {
|
||||
var query = new Builder(this);
|
||||
@ -975,11 +975,11 @@
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
|
||||
// All of the Schame methods that should be called with a
|
||||
// `SchemaBuilder` context, to disallow calling more than one method at once.
|
||||
var SchemaInterface = {
|
||||
|
||||
|
||||
// Modify a table on the schema.
|
||||
table: function(callback) {
|
||||
this.callback(callback);
|
||||
@ -1051,7 +1051,7 @@
|
||||
for (var i = 0, l = this.columns.length; i < l; i++) {
|
||||
var column = this.columns[i];
|
||||
var indices = ['primary', 'unique', 'index'];
|
||||
|
||||
|
||||
continueIndex:
|
||||
for (var i2 = 0, l2 = indices.length; i2 < l2; i2++) {
|
||||
var index = indices[i2];
|
||||
@ -1063,7 +1063,7 @@
|
||||
if (column[indexVar] === true) {
|
||||
this[index](column);
|
||||
continue continueIndex;
|
||||
|
||||
|
||||
// If the index has been specified on the column and it is something
|
||||
// other than boolean true, we will assume a name was provided on
|
||||
// the index specification, and pass in the name to the method.
|
||||
@ -1369,7 +1369,7 @@
|
||||
};
|
||||
|
||||
Knex.SchemaGrammar = {
|
||||
|
||||
|
||||
// Compile a foreign key command.
|
||||
compileForeign: function(blueprint, command) {
|
||||
var table = this.wrapTable(blueprint);
|
||||
@ -1405,7 +1405,7 @@
|
||||
}
|
||||
return columns;
|
||||
},
|
||||
|
||||
|
||||
// Add the column modifiers to the definition.
|
||||
addModifiers: function(sql, blueprint, column) {
|
||||
for (var i = 0, l = this.modifiers.length; i < l; i++) {
|
||||
@ -1489,8 +1489,8 @@
|
||||
|
||||
// Sorts an object based on the names.
|
||||
var sortObject = function(obj) {
|
||||
return _.sortBy(_.pairs(obj), function(a) {
|
||||
return a[0];
|
||||
return _.sortBy(_.pairs(obj), function(a) {
|
||||
return a[0];
|
||||
});
|
||||
};
|
||||
|
||||
@ -1506,11 +1506,11 @@
|
||||
|
||||
// Knex.Initialize
|
||||
// -------
|
||||
|
||||
|
||||
// Takes a hash of options to initialize the database
|
||||
// connection. The `client` is required to choose which client
|
||||
// path above is loaded, or to specify a custom path to a client.
|
||||
// Other options, such as `connection` or `pool` are passed
|
||||
// Other options, such as `connection` or `pool` are passed
|
||||
// into `client.initialize`.
|
||||
Knex.Initialize = function(name, options) {
|
||||
var Target, ClientCtor, client;
|
||||
@ -1521,7 +1521,7 @@
|
||||
options = name;
|
||||
name = 'main';
|
||||
}
|
||||
|
||||
|
||||
// Don't try to initialize the same `name` twice... If necessary,
|
||||
// delete the instance from `Knex.Instances`.
|
||||
if (Knex.Instances[name]) {
|
||||
@ -1529,7 +1529,7 @@
|
||||
}
|
||||
|
||||
client = options.client;
|
||||
|
||||
|
||||
if (!client) throw new Error('The client is required to use Knex.');
|
||||
|
||||
// Checks if this is a default client. If it's not,
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "knex",
|
||||
"version": "0.1.3",
|
||||
"version": "0.1.4",
|
||||
"description": "A fun, multi-dialect SQL query builder.",
|
||||
"main": "knex.js",
|
||||
"directories": {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user