8 lines
27 KiB
Plaintext
8 lines
27 KiB
Plaintext
|
{
|
||
|
"version": 3,
|
||
|
"sources": ["../../../src/dialects/mysql/query-generator.js"],
|
||
|
"sourcesContent": ["'use strict';\n\nconst _ = require('lodash');\nconst Utils = require('../../utils');\nconst AbstractQueryGenerator = require('../abstract/query-generator');\nconst util = require('util');\nconst Op = require('../../operators');\n\n\nconst JSON_FUNCTION_REGEX = /^\\s*((?:[a-z]+_){0,2}jsonb?(?:_[a-z]+){0,2})\\([^)]*\\)/i;\nconst JSON_OPERATOR_REGEX = /^\\s*(->>?|@>|<@|\\?[|&]?|\\|{2}|#-)/i;\nconst TOKEN_CAPTURE_REGEX = /^\\s*((?:([`\"'])(?:(?!\\2).|\\2{2})*\\2)|[\\w\\d\\s]+|[().,;+-])/i;\nconst FOREIGN_KEY_FIELDS = [\n 'CONSTRAINT_NAME as constraint_name',\n 'CONSTRAINT_NAME as constraintName',\n 'CONSTRAINT_SCHEMA as constraintSchema',\n 'CONSTRAINT_SCHEMA as constraintCatalog',\n 'TABLE_NAME as tableName',\n 'TABLE_SCHEMA as tableSchema',\n 'TABLE_SCHEMA as tableCatalog',\n 'COLUMN_NAME as columnName',\n 'REFERENCED_TABLE_SCHEMA as referencedTableSchema',\n 'REFERENCED_TABLE_SCHEMA as referencedTableCatalog',\n 'REFERENCED_TABLE_NAME as referencedTableName',\n 'REFERENCED_COLUMN_NAME as referencedColumnName'\n].join(',');\n\nconst typeWithoutDefault = new Set(['BLOB', 'TEXT', 'GEOMETRY', 'JSON']);\n\nclass MySQLQueryGenerator extends AbstractQueryGenerator {\n constructor(options) {\n super(options);\n\n this.OperatorMap = {\n ...this.OperatorMap,\n [Op.regexp]: 'REGEXP',\n [Op.notRegexp]: 'NOT REGEXP'\n };\n }\n\n createDatabaseQuery(databaseName, options) {\n options = {\n charset: null,\n collate: null,\n ...options\n };\n\n return Utils.joinSQLFragments([\n 'CREATE DATABASE IF NOT EXISTS',\n this.quoteIdentifier(databaseName),\n options.charset && `DEFAULT CHARACTER SET ${this.escape(options.charset)}`,\n options.collate && `DEFAULT COLLATE ${this.escape(options.collate)}`,\n ';'\n ]);\n }\n\n dropDatabaseQuery(databaseName) {\n return `DROP DATABASE IF EXISTS ${this.quoteIdentifier(databaseName)};`;\n }\n\n createSchema() {\n return 'SHOW TABLES';\n }\n\n showSchemasQuery() {\n return 'SHOW TABLES';\n }\n\n versionQuery() {\n return 'SELECT VERSION() as `version`';\n }\n\n createTableQuery(tableName, attributes, options) {\n options = {\n engine: 'InnoDB',\n charset: null,\n rowFormat: null,\n ...options\n };\n\n const primaryKeys = [];\n const foreignKeys = {};\n const attrStr = [];\n\n for (const attr in attributes) {\n if (!Object.prototype.hasOwnProperty.call(attributes, attr)) continue;\n const dataType = attributes[attr];\n let match;\n\n if (dataType.includes('PRIMARY KEY')) {\n primaryKeys.push(attr);\n\n if (dataType.includes('REFERENCES')) {\n // MySQL doesn't support inline REFERENCES declarations: move to the end\n match = dataType.match(/^(.+) (REFERENCES.*)$/);\n attrStr.push(`${this.quoteIdentifier(attr)} ${match[1].replace('PRIMARY KEY', '')}`);\n foreignKeys[attr] = match[2];\n } else {\n attrStr.push(`${this.quoteIdentifier(attr)} ${dataType.replace('PRIMARY KEY', '')}`);\n }\n } else if (dataType.includes('REFERENCES')) {\n // MySQL doesn't support inline REFERENCES declarations: move to the end\n match = dataType.match(/^(.+) (REFERENCES.*)$/);\n attrStr.push(`${this.quoteIdentifier(attr)} ${match[1]}`);\n foreignKeys[attr] = match[2];\n } else {\n attrStr.push(`${this.quoteIdentifier(attr)} ${dataType}`);\n }\n }\n\n const table = this.quoteTable(tableName);\n let attributesClause = attrStr.join(', ');\n const pkString = primaryKeys.map(pk => this.quoteIdentifier(pk)).join(', ');\n\n if (options.uniqueKeys) {\n _.each(options.uniqueKeys, (columns, indexName) => {\n if (columns.customIndex) {\n if (typeof indexName !== 'string') {\n indexName = `uniq_${tableName}_${columns.fields.join('_')}`;\n }\n attributesClause += `, UNIQUE ${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