compileInsert: function(qb, values) {
var table = this.wrapTable(qb.table);
var columns = this.columnize(_.keys(values[0]));
- var parameters = this.parameterize(values[0]);
+ var parameters = this.parameterize(_.values(values[0]));
var paramBlocks = [];
for (var i = 0, l = values.length; i < l; ++i) {
@@ -692,23 +692,6 @@ inserts using a single query statement.
- Compiles an insert, getting the id of the insert row.
-
- compileInsertGetId: function(qb, values) {
- return this.compileInsert(qb, values);
- },Compiles an update query.
Compiles a delete query.
Compiles a truncate query.
Knex.Builder
@@ -817,11 +800,11 @@ inserts using a single query statement. -Sets the tableName on the query.
Set the idAttribute for the query.
idAttribute: function(id) {
- this.idAttr = id;
- return this;
- },Adds a distinct clause to the query.
Clones the current query builder, including any pieces that have been set thus far
@@ -923,7 +886,7 @@ pieces that have been set thus far clone: function() {
var item = new Builder(this.table);
var items = [
- 'isDistinct', 'idAttr', 'joins',
+ 'isDistinct', 'joins',
'wheres', 'orders', 'columns', 'bindings',
'grammar', 'connection', 'transaction'
];
@@ -937,11 +900,11 @@ pieces that have been set thus far
- Resets all attributes on the query builder.
@@ -953,7 +916,6 @@ pieces that have been set thus far this.orders = []; this.columns = []; this.bindings = []; - this.idAttr = Builder.prototype.idAttr; this.isDistinct = false; }, @@ -964,7 +926,6 @@ pieces that have been set thus far order: this.orders, columns: this.columns, bindings: this.bindings, - idAttr: this.idAttr, isDistinct: this.isDistinct }; },Adds a join clause to the query, allowing for advanced joins with an anonymous function as the second argument.
@@ -1000,11 +961,11 @@ with an anonymous function as the second argument. -The where function can be used in several ways:
The most basic is where(key, value), which expands to
@@ -1046,11 +1007,11 @@ where key = value.
Alias to where, for internal builder consistency.
Adds an or where clause to the query.
Adds a where exists clause to the query.
Adds an or where exists clause to the query.
Adds a where not exists clause to the query.
Adds a or where not exists clause to the query.
Adds a where in clause to the query.
Adds a or where in clause to the query.
Adds a where not in clause to the query.
Adds a or where not in clause to the query.
Adds a where null clause to the query.
Adds a or where null clause to the query.
Adds a where not null clause to the query.
Adds a or where not null clause to the query.
Adds a where between clause to the query.
Adds a or where between clause to the query.
@@ -1368,11 +1329,11 @@ where key = value. -
Adds a group by clause to the query.
Adds a order by clause to the query.
Adds a having clause to the query.
+ +
offset: function(value) {
+ if (value == null) return this.isOffset;
+ this.isOffset = value;
+ return this;
+ },
+
+ limit: function(value) {
+ if (value == null) return this.isLimit;
+ this.isLimit = value;
+ return this;
+ }, offset: function(value) {
- if (value == null) return this.isOffset;
- this.isOffset = value;
- return this;
- },
-
- limit: function(value) {
- if (value == null) return this.isLimit;
- this.isLimit = value;
- return this;
- },- -
Determine if any rows exist for the current query.
Retrieve the "count" result of the query.
@@ -1509,11 +1470,11 @@ where key = value. -Retrieve the minimum value of a given column.
@@ -1526,11 +1487,11 @@ where key = value. -Retrieve the maximum value of a given column.
@@ -1543,11 +1504,11 @@ where key = value. -Retrieve the sum of the values of a given column.
@@ -1560,11 +1521,11 @@ where key = value. -Increments a column's value by the specified amount.
@@ -1577,11 +1538,11 @@ where key = value. -Decrements a column's value by the specified amount.
@@ -1594,11 +1555,11 @@ where key = value. -Performs a select query, returning a promise.
insert: function(values, returning) {
- var str;
- returning || (returning = this.idAttr);
if (!_.isArray(values)) values = values ? [values] : [];
for (var i = 0, l = values.length; i < l; i++) {
var record = values[i];
this.bindings = this.bindings.concat(_.values(record));
}
- if (returning) {
- str = this.grammar.compileInsertGetId(this, values, returning);
- } else {
- str = this.grammar.compileInsert(this, values);
- }
+ var str = this.grammar.compileInsert(this, values);
return Knex.runQuery(this, {sql: str, bindings: this._cleanBindings(), type: 'insert'});
},Performs an update query, returning a promise.
Executes a delete statement on the query;
@@ -1679,11 +1634,11 @@ where key = value. -Alias to delete
@@ -1696,11 +1651,11 @@ where key = value. -Truncate
@@ -1713,11 +1668,11 @@ where key = value. -Set by transacting - contains the object with the connection
needed to execute a transaction
Sets the current Builder connection to that of the the currently running transaction
@@ -1748,11 +1703,11 @@ the currently running transaction -@@ -1761,11 +1716,11 @@ the currently running transaction -
Returns all bindings excluding the Knex.Raw types.
Knex.JoinClause
@@ -1853,11 +1808,11 @@ the currently running transaction -Knex.Transaction
@@ -1898,11 +1853,11 @@ the currently running transaction -Initiate a deferred object, so we know when the transaction completes or fails, we know what to do.
@@ -1930,11 +1885,11 @@ transaction completes or fails, we know what to do. -Finish the transaction connection
@@ -1949,11 +1904,11 @@ transaction completes or fails, we know what to do. -Call the container with the transaction commit & rollback objects
@@ -1972,11 +1927,11 @@ commit & rollback objects -Knex.Schema
@@ -1985,11 +1940,11 @@ commit & rollback objects -Top level object for Schema related functions
@@ -2000,11 +1955,11 @@ commit & rollback objects -Attach main static methods, which passthrough to the SchemaBuilder instance methods
@@ -2022,11 +1977,11 @@ SchemaBuilder instance methods -Knex.SchemaBuilder
@@ -2035,11 +1990,11 @@ SchemaBuilder instance methods -Connection
@@ -2078,11 +2033,11 @@ SchemaBuilder instance methods -Used before a builder call, specifying if this call is nested inside a transaction
@@ -2097,11 +2052,11 @@ is nested inside a transaction -Determine if the given table exists.
@@ -2124,11 +2079,11 @@ is nested inside a transaction -Modify a table on the schema.
@@ -2141,11 +2096,11 @@ is nested inside a transaction -Create a new table on the schema.
@@ -2161,11 +2116,11 @@ is nested inside a transaction -Drop a table from the schema.
@@ -2180,11 +2135,11 @@ is nested inside a transaction -Drop a table from the schema if it exists.
@@ -2199,11 +2154,11 @@ is nested inside a transaction -Rename a table on the schema.
@@ -2218,11 +2173,11 @@ is nested inside a transaction -Execute the blueprint to build / modify the table.
@@ -2235,11 +2190,11 @@ is nested inside a transaction -Create a new command set with a Closure.
@@ -2253,11 +2208,11 @@ is nested inside a transaction -Knex.SchemaGrammar
@@ -2266,11 +2221,11 @@ is nested inside a transaction -Compile a foreign key command.
@@ -2301,11 +2256,11 @@ is nested inside a transaction -We need to prepare several of the elements of the foreign key definition before we can create the SQL, such as wrapping the tables and convert @@ -2322,11 +2277,11 @@ an array of columns to comma-delimited strings for the SQL queries.
-Once we have the basic foreign key creation statement constructed we can build out the syntax for what should happen on an update or delete of @@ -2343,11 +2298,11 @@ the affected columns, which will get something like "cascade", etc.
-Each of the column types have their own compiler functions which are responsible for turning the column definition into its SQL format @@ -2369,11 +2324,11 @@ for the platform. Then column modifiers are compiled and added.
-Add the column modifiers to the definition.
@@ -2393,11 +2348,11 @@ for the platform. Then column modifiers are compiled and added. -Get the primary key command if it exists on the blueprint.
@@ -2411,11 +2366,11 @@ for the platform. Then column modifiers are compiled and added. -Get all of the commands with a given name.
@@ -2428,11 +2383,11 @@ for the platform. Then column modifiers are compiled and added. -Get the SQL for the column data type.
@@ -2445,11 +2400,11 @@ for the platform. Then column modifiers are compiled and added. -Add a prefix to an array of values.
@@ -2462,11 +2417,11 @@ for the platform. Then column modifiers are compiled and added. -Wrap a table in keyword identifiers.
@@ -2480,11 +2435,11 @@ for the platform. Then column modifiers are compiled and added. -Wrap a value in keyword identifiers.
@@ -2498,11 +2453,11 @@ for the platform. Then column modifiers are compiled and added. -Format a value so that it can be used in "default" clauses.
@@ -2519,11 +2474,11 @@ for the platform. Then column modifiers are compiled and added. -Knex.SchemaBlueprint
@@ -2532,11 +2487,11 @@ for the platform. Then column modifiers are compiled and added. -Get the raw sql statements for the blueprint.
@@ -2578,11 +2533,11 @@ for the platform. Then column modifiers are compiled and added. -Add the commands that are implied by the blueprint.
@@ -2595,11 +2550,11 @@ for the platform. Then column modifiers are compiled and added. -Add indicies
@@ -2617,11 +2572,11 @@ for the platform. Then column modifiers are compiled and added. -If the index has been specified on the given column, but is simply equal to "true" (boolean), no name has been specified for this @@ -2636,11 +2591,11 @@ index, so we will simply call the index methods without one.
-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 @@ -2660,11 +2615,11 @@ the index specification, and pass in the name to the method.
-Each type of command has a corresponding compiler function on the schema grammar which is used to build the necessary SQL statements to build @@ -2687,11 +2642,11 @@ the blueprint element, so we'll just call that compilers function.
-Determine if the blueprint has a create command.
@@ -2709,11 +2664,11 @@ the blueprint element, so we'll just call that compilers function. -Indicate that the table needs to be created.
@@ -2726,11 +2681,11 @@ the blueprint element, so we'll just call that compilers function. -Indicate that the table should be dropped.
@@ -2743,11 +2698,11 @@ the blueprint element, so we'll just call that compilers function. -Indicate that the table should be dropped if it exists.
@@ -2760,11 +2715,11 @@ the blueprint element, so we'll just call that compilers function. -Indicate that the given columns should be dropped.
@@ -2778,11 +2733,11 @@ the blueprint element, so we'll just call that compilers function. -Indicate that the given columns should be dropped.
@@ -2795,11 +2750,11 @@ the blueprint element, so we'll just call that compilers function. -Indicate that the given primary key should be dropped.
@@ -2812,11 +2767,11 @@ the blueprint element, so we'll just call that compilers function. -Indicate that the given unique key should be dropped.
@@ -2829,11 +2784,11 @@ the blueprint element, so we'll just call that compilers function. -Indicate that the given index should be dropped.
@@ -2846,11 +2801,11 @@ the blueprint element, so we'll just call that compilers function. -Indicate that the given foreign key should be dropped.
@@ -2863,11 +2818,11 @@ the blueprint element, so we'll just call that compilers function. -Rename the table to a given name.
@@ -2880,11 +2835,11 @@ the blueprint element, so we'll just call that compilers function. -Specify the primary key(s) for the table.
@@ -2897,11 +2852,11 @@ the blueprint element, so we'll just call that compilers function. -Specify a unique index for the table.
@@ -2914,11 +2869,11 @@ the blueprint element, so we'll just call that compilers function. -Specify an index for the table.
@@ -2931,11 +2886,11 @@ the blueprint element, so we'll just call that compilers function. -Specify a foreign key for the table.
@@ -2948,11 +2903,11 @@ the blueprint element, so we'll just call that compilers function. -Create a new auto-incrementing column on the table.
@@ -2966,11 +2921,11 @@ the blueprint element, so we'll just call that compilers function. -Create a new string column on the table.
@@ -2983,11 +2938,11 @@ the blueprint element, so we'll just call that compilers function. -Create a new text column on the table.
@@ -3000,11 +2955,11 @@ the blueprint element, so we'll just call that compilers function. -Create a new integer column on the table.
@@ -3017,11 +2972,11 @@ the blueprint element, so we'll just call that compilers function. -Create a new float column on the table.
@@ -3034,11 +2989,11 @@ the blueprint element, so we'll just call that compilers function. -Create a new decimal column on the table.
@@ -3051,11 +3006,11 @@ the blueprint element, so we'll just call that compilers function. -Create a new boolean column on the table.
@@ -3068,11 +3023,11 @@ the blueprint element, so we'll just call that compilers function. -Alias to "boolean".
@@ -3085,11 +3040,11 @@ the blueprint element, so we'll just call that compilers function. -Create a new date column on the table.
@@ -3102,11 +3057,11 @@ the blueprint element, so we'll just call that compilers function. -Create a new date-time column on the table.
@@ -3119,11 +3074,11 @@ the blueprint element, so we'll just call that compilers function. -Create a new time column on the table.
@@ -3136,11 +3091,11 @@ the blueprint element, so we'll just call that compilers function. -Create a new timestamp column on the table.
@@ -3153,11 +3108,11 @@ the blueprint element, so we'll just call that compilers function. -Add creation and update timestamps to the table.
@@ -3171,11 +3126,11 @@ the blueprint element, so we'll just call that compilers function. -Create a new enum column on the table.
@@ -3188,11 +3143,11 @@ the blueprint element, so we'll just call that compilers function. -Alias to enum.
@@ -3205,11 +3160,11 @@ the blueprint element, so we'll just call that compilers function. -Create a new binary column on the table.
@@ -3222,11 +3177,11 @@ the blueprint element, so we'll just call that compilers function. -@@ -3235,11 +3190,11 @@ the blueprint element, so we'll just call that compilers function. -
Create a new drop index command on the blueprint.
@@ -3257,11 +3212,11 @@ the blueprint element, so we'll just call that compilers function. -Add a new index command to the blueprint. If no name was specified for this index, we will create one using a basic @@ -3283,11 +3238,11 @@ index type, such as primary or index, which makes the index unique.
-Add a new column to the blueprint.
@@ -3304,11 +3259,11 @@ index type, such as primary or index, which makes the index unique. -Add a new command to the blueprint.
@@ -3324,11 +3279,11 @@ index type, such as primary or index, which makes the index unique. -Chainable object used in creating SchemaBuilder commands.
@@ -3343,11 +3298,11 @@ index type, such as primary or index, which makes the index unique. -Sets the default value for a column.
@@ -3361,11 +3316,11 @@ index type, such as primary or index, which makes the index unique. -Sets an integer as unsigned, is a no-op if the column type is not an integer.
@@ -3380,11 +3335,11 @@ if the column type is not an integer. -Allows the column to contain null values.
@@ -3419,11 +3374,11 @@ if the column type is not an integer. -Knex.Raw
@@ -3432,11 +3387,11 @@ if the column type is not an integer. -Knex.runQuery
@@ -3461,11 +3416,11 @@ if the column type is not an integer. -Query runner, the context of this function is set to the caller, (either Builder or SchemaBuilder). Checks and fails on an already @@ -3490,11 +3445,11 @@ and returns a deferred promise.
-Export the Knex module
diff --git a/index.js b/index.js deleted file mode 100644 index 710aeb43..00000000 --- a/index.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require('./knex'); \ No newline at end of file diff --git a/knex.js b/knex.js index 0c5e70d9..4444d19b 100644 --- a/knex.js +++ b/knex.js @@ -249,7 +249,7 @@ compileInsert: function(qb, values) { var table = this.wrapTable(qb.table); var columns = this.columnize(_.keys(values[0])); - var parameters = this.parameterize(values[0]); + var parameters = this.parameterize(_.values(values[0])); var paramBlocks = []; for (var i = 0, l = values.length; i < l; ++i) { @@ -259,11 +259,6 @@ return "insert into " + table + " (" + columns + ") values " + paramBlocks.join(', '); }, - // Compiles an `insert`, getting the id of the insert row. - compileInsertGetId: function(qb, values) { - return this.compileInsert(qb, values); - }, - // Compiles an `update` query. compileUpdate: function(qb, values) { var table = this.wrapTable(qb.table), columns = []; @@ -342,8 +337,6 @@ Builder.prototype = { - idAttr: 'id', - // Sets the `tableName` on the query. from: function(tableName) { if (!tableName) return this.table; @@ -351,12 +344,6 @@ return this; }, - // Set the `idAttribute` for the query. - idAttribute: function(id) { - this.idAttr = id; - return this; - }, - // Adds a `distinct` clause to the query. distinct: function() { this.isDistinct = true; @@ -368,7 +355,7 @@ clone: function() { var item = new Builder(this.table); var items = [ - 'isDistinct', 'idAttr', 'joins', + 'isDistinct', 'joins', 'wheres', 'orders', 'columns', 'bindings', 'grammar', 'connection', 'transaction' ]; @@ -386,7 +373,6 @@ this.orders = []; this.columns = []; this.bindings = []; - this.idAttr = Builder.prototype.idAttr; this.isDistinct = false; }, @@ -397,7 +383,6 @@ order: this.orders, columns: this.columns, bindings: this.bindings, - idAttr: this.idAttr, isDistinct: this.isDistinct }; }, @@ -654,18 +639,12 @@ // Performs an `INSERT` query, returning a promise. insert: function(values, returning) { - var str; - returning || (returning = this.idAttr); if (!_.isArray(values)) values = values ? [values] : []; for (var i = 0, l = values.length; i < l; i++) { var record = values[i]; this.bindings = this.bindings.concat(_.values(record)); } - if (returning) { - str = this.grammar.compileInsertGetId(this, values, returning); - } else { - str = this.grammar.compileInsert(this, values); - } + var str = this.grammar.compileInsert(this, values); return Knex.runQuery(this, {sql: str, bindings: this._cleanBindings(), type: 'insert'}); }, diff --git a/package.json b/package.json index 97d14cf1..6bc1459b 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "knex", "version": "0.0.0", "description": "a fun sql query builder", - "main": "index.js", + "main": "knex.js", "directories": { "test": "test" }, From 4d3852528a14f006f745692410820c1bbcd044cd Mon Sep 17 00:00:00 2001 From: Tim Griesser increments: function(column) {
- column || (column = 'id');
- return this._addColumn('integer', column, {autoIncrement: true});
+ return this._addColumn('integer', (column || 'id'), {autoIncrement: true});
},Create a new text column on the table.
+Alias varchar to string
text: function(column) {
- return this._addColumn('text', column);
+ varchar: