knex/src/dialects/mssql/schema/columncompiler.js

114 lines
2.4 KiB
JavaScript
Raw Normal View History

2016-03-02 17:07:05 +01:00
// MySQL Column Compiler
// -------
import inherits from 'inherits';
import ColumnCompiler from '../../../schema/columncompiler';
2016-03-02 17:07:05 +01:00
import { assign } from 'lodash'
2016-03-02 17:07:05 +01:00
function ColumnCompiler_MSSQL() {
ColumnCompiler.apply(this, arguments);
this.modifiers = ['nullable', 'defaultTo', 'first', 'after', 'comment']
}
inherits(ColumnCompiler_MSSQL, ColumnCompiler);
// Types
// ------
assign(ColumnCompiler_MSSQL.prototype, {
increments: 'int identity(1,1) not null primary key',
bigincrements: 'bigint identity(1,1) not null primary key',
bigint: 'bigint',
double(precision, scale) {
if (!precision) return 'decimal'
return `decimal(${this._num(precision, 8)}, ${this._num(scale, 2)})`
},
floating(precision, scale) {
if (!precision) return 'decimal'
return `decimal(${this._num(precision, 8)}, ${this._num(scale, 2)})`
2016-03-02 17:07:05 +01:00
},
integer(length) {
length = length ? `(${this._num(length, 11)})` : ''
return `int${length}`
2016-03-02 17:07:05 +01:00
},
mediumint: 'int',
2016-03-02 17:07:05 +01:00
smallint: 'smallint',
tinyint(length) {
length = length ? `(${this._num(length, 1)})` : ''
return `tinyint${length}`
2016-03-02 17:07:05 +01:00
},
varchar(length) {
return `nvarchar(${this._num(length, 255)})`;
2016-03-02 17:07:05 +01:00
},
text: 'nvarchar(max)',
mediumtext: 'nvarchar(max)',
longtext: 'nvarchar(max)',
Add redshift support without changing cli or package.json (#2233) * Add a Redshift dialect that inherits from Postgres. * Turn .index() and .dropIndex() into no-ops with warnings in the Redshift dialect. * Update the Redshift dialect to be compatible with master. * Update package.json * Disable liftoff cli * Remove the CLI * Add lib to the repo * Allow the escaping of named bindings. * Update dist * Update the Redshift dialect’s instantiation of the query and column compilers. * Update the distribution * Fix a merge conflict * Take lib back out * Trying to bring back in line with tgreisser/knex * Add npm 5 package-lock * Bring cli.js back in line * Bring cli.js back in line * Progress commit on redshift integration tests * Revert "Progress commit on redshift integration tests" This reverts commit 207e31635c638853dec54ce0580d34559ba5a54c. * Progress commit * Working not null on primary columns in createTable * Working redshift unit tests * Working unit and integration tests, still need to fix migration tests * Brought datatypes more in line with what redshift actually supports * Added query compiler unit tests * Add a hacky returning clause for redshift ugh * Working migration integration tests * Working insert integration tests * Allow multiple insert returning values * Working select integration tests * Working join integration tests * Working aggregate integration tests * All integration suite tests working * Put docker index for reconnect tests back * Redshift does not support insert...returning, there does not seem to be a way around that, therefore accept it and test accordingly * Leave redshift integration tests in place, but do not run them by default * Fix mysql order by test * Fix more tests * Change test db name to knex_test for consistency * Address PR comments
2018-02-03 08:33:02 -05:00
// TODO: mssql supports check constraints as of SQL Server 2008
// so make enu here more like postgres
2016-03-02 17:07:05 +01:00
enu: 'nvarchar(100)',
uuid: 'uniqueidentifier',
datetime: 'datetime',
timestamp: 'datetime',
bit(length) {
if (length > 1) {
this.client.logger.warn('Bit field is exactly 1 bit length for MSSQL');
}
return 'bit';
2016-03-02 17:07:05 +01:00
},
binary(length) {
2016-06-01 02:42:17 +03:00
return length ? `varbinary(${this._num(length)})` : 'varbinary(max)'
2016-03-02 17:07:05 +01:00
},
bool: 'bit',
// Modifiers
// ------
defaultTo(value) {
const defaultVal = ColumnCompiler_MSSQL.super_.prototype.defaultTo.apply(this, arguments);
2016-03-02 17:07:05 +01:00
if (this.type !== 'blob' && this.type.indexOf('text') === -1) {
return defaultVal
}
return ''
},
first() {
this.client.logger.warn('Column first modifier not available for MSSQL');
return '';
2016-03-02 17:07:05 +01:00
},
after(column) {
this.client.logger.warn('Column after modifier not available for MSSQL');
return '';
2016-03-02 17:07:05 +01:00
},
comment(comment) {
2016-03-02 17:07:05 +01:00
if (comment && comment.length > 255) {
this.client.logger.warn('Your comment is longer than the max comment length for MSSQL')
2016-03-02 17:07:05 +01:00
}
return ''
}
})
export default ColumnCompiler_MSSQL;