// MySQL Column Compiler // ------- const ColumnCompiler = require('../../../schema/columncompiler'); const { isObject } = require('../../../util/is'); const { toNumber } = require('../../../util/helpers'); const commentEscapeRegex = /(? 255) { this.client.logger.warn( 'Your comment is longer than the max comment length for MySQL' ); } return comment && `comment '${comment.replace(commentEscapeRegex, "\\'")}'`; } first() { return 'first'; } after(column) { return `after ${this.formatter.wrap(column)}`; } collate(collation) { return collation && `collate '${collation}'`; } checkRegex(regex, constraintName) { return this._check( `${this.formatter.wrap( this.getColumnName() )} REGEXP ${this.client._escapeBinding(regex)}`, constraintName ); } increments(options = { primaryKey: true }) { return ( 'int unsigned not null' + // In MySQL autoincrement are always a primary key. If you already have a primary key, we // initialize this column as classic int column then modify it later in table compiler (this.tableCompiler._canBeAddPrimaryKey(options) ? ' auto_increment primary key' : '') ); } bigincrements(options = { primaryKey: true }) { return ( 'bigint unsigned not null' + // In MySQL autoincrement are always a primary key. If you already have a primary key, we // initialize this column as classic int column then modify it later in table compiler (this.tableCompiler._canBeAddPrimaryKey(options) ? ' auto_increment primary key' : '') ); } } ColumnCompiler_MySQL.prototype.bigint = 'bigint'; ColumnCompiler_MySQL.prototype.mediumint = 'mediumint'; ColumnCompiler_MySQL.prototype.smallint = 'smallint'; module.exports = ColumnCompiler_MySQL;