mirror of
https://github.com/knex/knex.git
synced 2025-12-29 07:59:31 +00:00
adding bit column, integer constraint, other text types, other fixes
This commit is contained in:
parent
4d3852528a
commit
be2273d596
@ -94,7 +94,7 @@ var grammar = exports.grammar = {
|
||||
exports.schemaGrammar = _.extend({}, grammar, {
|
||||
|
||||
// The possible column modifiers.
|
||||
modifiers: ['Unsigned', 'Nullable', 'Default', 'Increment'],
|
||||
modifiers: ['Unsigned', 'Nullable', 'Default', 'Increment', 'After'],
|
||||
|
||||
// Compile the query to determine if a table exists.
|
||||
compileTableExists: function() {
|
||||
@ -174,7 +174,7 @@ exports.schemaGrammar = _.extend({}, grammar, {
|
||||
|
||||
// Compile a rename table command.
|
||||
compileRename: function(blueprint, command) {
|
||||
return "rename table " + this.wrapTable(blueprint) + " to " + this.wrapTable(command.to);
|
||||
return 'rename table ' + this.wrapTable(blueprint) + ' to ' + this.wrapTable(command.to);
|
||||
},
|
||||
|
||||
// Create the column definition for a string type.
|
||||
@ -184,12 +184,26 @@ exports.schemaGrammar = _.extend({}, grammar, {
|
||||
|
||||
// Create the column definition for a text type.
|
||||
typeText: function(column) {
|
||||
return 'text';
|
||||
switch (column.length) {
|
||||
case 'medium':
|
||||
case 'mediumtext':
|
||||
return 'mediumtext';
|
||||
case 'long':
|
||||
case 'longtext':
|
||||
return 'longtext';
|
||||
default:
|
||||
return 'text';
|
||||
}
|
||||
},
|
||||
|
||||
// Create the column definition for a integer type.
|
||||
typeInteger: function(column) {
|
||||
return 'int';
|
||||
return 'int(' + column.length + ')';
|
||||
},
|
||||
|
||||
// Create the column definition for a tiny integer type.
|
||||
typeTinyInteger: function() {
|
||||
return 'tinyint';
|
||||
},
|
||||
|
||||
// Create the column definition for a float type.
|
||||
@ -232,6 +246,11 @@ exports.schemaGrammar = _.extend({}, grammar, {
|
||||
return 'timestamp default 0';
|
||||
},
|
||||
|
||||
// Create the column definition for a bit type.
|
||||
typeBit: function(column) {
|
||||
return column.length !== false ? 'bit(' + column.length + ')' : 'bit';
|
||||
},
|
||||
|
||||
// Create the column definition for a binary type.
|
||||
typeBinary: function(column) {
|
||||
return 'blob';
|
||||
|
||||
@ -197,8 +197,7 @@ exports.schemaGrammar = _.extend({}, grammar, {
|
||||
|
||||
// Compile a rename table command.
|
||||
compileRename: function(blueprint, command) {
|
||||
var from = this.wrapTable(blueprint);
|
||||
return "alter table " + from + " rename to " + this.wrapTable(command.to);
|
||||
return 'alter table ' + this.wrapTable(blueprint) + ' rename to ' + this.wrapTable(command.to);
|
||||
},
|
||||
|
||||
// Create the column definition for a string type.
|
||||
@ -261,6 +260,11 @@ exports.schemaGrammar = _.extend({}, grammar, {
|
||||
return 'timestamp';
|
||||
},
|
||||
|
||||
// Create the column definition for a bit type.
|
||||
typeBit: function(column) {
|
||||
return column.length !== false ? 'bit(' + column.length + ')' : 'bit';
|
||||
},
|
||||
|
||||
// Create the column definition for a binary type.
|
||||
typeBinary: function(column) {
|
||||
return 'bytea';
|
||||
|
||||
@ -280,6 +280,11 @@ exports.schemaGrammar = _.extend({}, grammar, {
|
||||
typeBoolean: function(column) {
|
||||
return 'tinyint';
|
||||
},
|
||||
|
||||
// Create the column definition for a tinyint type.
|
||||
typeTinyInteger: function() {
|
||||
return 'tinyint';
|
||||
},
|
||||
|
||||
// Create the column definition for a enum type.
|
||||
typeEnum: function(column) {
|
||||
|
||||
28
knex.js
28
knex.js
@ -1151,8 +1151,7 @@
|
||||
|
||||
// Create a new auto-incrementing column on the table.
|
||||
increments: function(column) {
|
||||
column || (column = 'id');
|
||||
return this._addColumn('integer', column, {autoIncrement: true});
|
||||
return this._addColumn('integer', (column || 'id'), {autoIncrement: true});
|
||||
},
|
||||
|
||||
// Create a new string column on the table.
|
||||
@ -1160,14 +1159,24 @@
|
||||
return this._addColumn('string', column, {length: (length || 255)});
|
||||
},
|
||||
|
||||
// Alias varchar to string
|
||||
varchar: function(column, length) {
|
||||
return this.string(column, length);
|
||||
},
|
||||
|
||||
// Create a new text column on the table.
|
||||
text: function(column) {
|
||||
return this._addColumn('text', column);
|
||||
text: function(column, length) {
|
||||
return this._addColumn('text', column, {length: (length || false)});
|
||||
},
|
||||
|
||||
// Create a new integer column on the table.
|
||||
integer: function(column) {
|
||||
return this._addColumn('integer', column);
|
||||
integer: function(column, length) {
|
||||
return this._addColumn('integer', column, {length: (length || 11)});
|
||||
},
|
||||
|
||||
// Create a new tinyinteger column on the table.
|
||||
tinyInteger: function(column) {
|
||||
return this._addColumn('tinyInteger', column);
|
||||
},
|
||||
|
||||
// Create a new float column on the table.
|
||||
@ -1182,7 +1191,7 @@
|
||||
|
||||
// Create a new boolean column on the table.
|
||||
boolean: function(column) {
|
||||
return this.bool(columns);
|
||||
return this._addColumn('boolean', column);
|
||||
},
|
||||
|
||||
// Alias to "boolean".
|
||||
@ -1226,6 +1235,11 @@
|
||||
return this._addColumn('enum', column, {allowed: allowed});
|
||||
},
|
||||
|
||||
// Create a new bit column on the table.
|
||||
bit: function(column, length) {
|
||||
return this._addColumn('bit', column, {length: (length || false)});
|
||||
},
|
||||
|
||||
// Create a new binary column on the table.
|
||||
binary: function(column) {
|
||||
return this._addColumn('binary', column);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user