columncompiler.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. 'use strict';
  2. exports.__esModule = true;
  3. var _assign2 = require('lodash/assign');
  4. var _assign3 = _interopRequireDefault(_assign2);
  5. var _inherits = require('inherits');
  6. var _inherits2 = _interopRequireDefault(_inherits);
  7. var _columncompiler = require('../../../schema/columncompiler');
  8. var _columncompiler2 = _interopRequireDefault(_columncompiler);
  9. var _helpers = require('../../../helpers');
  10. var helpers = _interopRequireWildcard(_helpers);
  11. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
  12. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  13. function ColumnCompiler_MSSQL() {
  14. _columncompiler2.default.apply(this, arguments);
  15. this.modifiers = ['nullable', 'defaultTo', 'first', 'after', 'comment'];
  16. }
  17. // MySQL Column Compiler
  18. // -------
  19. (0, _inherits2.default)(ColumnCompiler_MSSQL, _columncompiler2.default);
  20. // Types
  21. // ------
  22. (0, _assign3.default)(ColumnCompiler_MSSQL.prototype, {
  23. increments: 'int identity(1,1) not null primary key',
  24. bigincrements: 'bigint identity(1,1) not null primary key',
  25. bigint: 'bigint',
  26. double: function double(precision, scale) {
  27. if (!precision) return 'decimal';
  28. return 'decimal(' + this._num(precision, 8) + ', ' + this._num(scale, 2) + ')';
  29. },
  30. floating: function floating(precision, scale) {
  31. if (!precision) return 'decimal';
  32. return 'decimal(' + this._num(precision, 8) + ', ' + this._num(scale, 2) + ')';
  33. },
  34. integer: function integer(length) {
  35. length = length ? '(' + this._num(length, 11) + ')' : '';
  36. return 'int' + length;
  37. },
  38. mediumint: 'int',
  39. smallint: 'smallint',
  40. tinyint: function tinyint(length) {
  41. length = length ? '(' + this._num(length, 1) + ')' : '';
  42. return 'tinyint' + length;
  43. },
  44. varchar: function varchar(length) {
  45. return 'nvarchar(' + this._num(length, 255) + ')';
  46. },
  47. text: 'nvarchar(max)',
  48. mediumtext: 'nvarchar(max)',
  49. longtext: 'nvarchar(max)',
  50. enu: 'nvarchar(100)',
  51. uuid: 'uniqueidentifier',
  52. datetime: 'datetime',
  53. timestamp: 'datetime',
  54. bit: function bit(length) {
  55. if (length > 1) {
  56. helpers.warn('Bit field is exactly 1 bit length for MSSQL');
  57. }
  58. return 'bit';
  59. },
  60. binary: function binary(length) {
  61. return length ? 'varbinary(' + this._num(length) + ')' : 'varbinary(max)';
  62. },
  63. bool: 'bit',
  64. // Modifiers
  65. // ------
  66. defaultTo: function defaultTo(value) {
  67. var defaultVal = ColumnCompiler_MSSQL.super_.prototype.defaultTo.apply(this, arguments);
  68. if (this.type !== 'blob' && this.type.indexOf('text') === -1) {
  69. return defaultVal;
  70. }
  71. return '';
  72. },
  73. first: function first() {
  74. helpers.warn('Column first modifier not available for MSSQL');
  75. return '';
  76. },
  77. after: function after(column) {
  78. helpers.warn('Column after modifier not available for MSSQL');
  79. return '';
  80. },
  81. comment: function comment(_comment) {
  82. if (_comment && _comment.length > 255) {
  83. helpers.warn('Your comment is longer than the max comment length for MSSQL');
  84. }
  85. return '';
  86. }
  87. });
  88. exports.default = ColumnCompiler_MSSQL;
  89. module.exports = exports['default'];