8 lines
50 KiB
Plaintext
8 lines
50 KiB
Plaintext
|
{
|
||
|
"version": 3,
|
||
|
"sources": ["../../../src/dialects/mssql/query-generator.js"],
|
||
|
"sourcesContent": ["'use strict';\n\nconst _ = require('lodash');\nconst Utils = require('../../utils');\nconst DataTypes = require('../../data-types');\nconst TableHints = require('../../table-hints');\nconst AbstractQueryGenerator = require('../abstract/query-generator');\nconst randomBytes = require('crypto').randomBytes;\nconst semver = require('semver');\nconst Op = require('../../operators');\n\n/* istanbul ignore next */\nconst throwMethodUndefined = function(methodName) {\n throw new Error(`The method \"${methodName}\" is not defined! Please add it to your sql dialect.`);\n};\n\nclass MSSQLQueryGenerator extends AbstractQueryGenerator {\n createDatabaseQuery(databaseName, options) {\n options = { collate: null, ...options };\n\n const collation = options.collate ? `COLLATE ${this.escape(options.collate)}` : '';\n\n return [\n 'IF NOT EXISTS (SELECT * FROM sys.databases WHERE name =', wrapSingleQuote(databaseName), ')',\n 'BEGIN',\n 'CREATE DATABASE', this.quoteIdentifier(databaseName),\n `${collation};`,\n 'END;'\n ].join(' ');\n }\n\n dropDatabaseQuery(databaseName) {\n return [\n 'IF EXISTS (SELECT * FROM sys.databases WHERE name =', wrapSingleQuote(databaseName), ')',\n 'BEGIN',\n 'DROP DATABASE', this.quoteIdentifier(databaseName), ';',\n 'END;'\n ].join(' ');\n }\n\n createSchema(schema) {\n return [\n 'IF NOT EXISTS (SELECT schema_name',\n 'FROM information_schema.schemata',\n 'WHERE schema_name =', wrapSingleQuote(schema), ')',\n 'BEGIN',\n \"EXEC sp_executesql N'CREATE SCHEMA\",\n this.quoteIdentifier(schema),\n \";'\",\n 'END;'\n ].join(' ');\n }\n\n dropSchema(schema) {\n // Mimics Postgres CASCADE, will drop objects belonging to the schema\n const quotedSchema = wrapSingleQuote(schema);\n return [\n 'IF EXISTS (SELECT schema_name',\n 'FROM information_schema.schemata',\n 'WHERE schema_name =', quotedSchema, ')',\n 'BEGIN',\n 'DECLARE @id INT, @ms_sql NVARCHAR(2000);',\n 'DECLARE @cascade TABLE (',\n 'id INT NOT NULL IDENTITY PRIMARY KEY,',\n 'ms_sql NVARCHAR(2000) NOT NULL );',\n 'INSERT INTO @cascade ( ms_sql )',\n \"SELECT CASE WHEN o.type IN ('F','PK')\",\n \"THEN N'ALTER TABLE ['+ s.name + N'].[' + p.name + N'] DROP CONSTRAINT [' + o.name + N']'\",\n \"ELSE N'DROP TABLE ['+ s.name + N'].[' + o.name + N']' END\",\n 'FROM sys.objects o',\n 'JOIN sys.schemas s on o.schema_id = s.schema_id',\n 'LEFT OUTER JOIN sys.objects p on o.parent_object_id = p.object_id',\n \"WHERE o.type IN ('F', 'PK', 'U') AND s.name = \", quotedSchema,\n 'ORDER BY o.type ASC;',\n 'SELECT TOP 1 @id = id, @ms_sql = ms_sql FROM @cascade ORDER BY id;',\n 'WHILE @id IS NOT NULL',\n 'BEGIN',\n 'BEGIN TRY EXEC sp_executesql @ms_sql; END TRY',\n 'BEGIN CATCH BREAK; THROW; END CATCH;',\n 'DELETE FROM @cascade WHERE id = @id;',\n 'SELECT @id = NULL, @ms_sql = NULL;',\n 'SELECT TOP 1 @id = id, @ms_sql = ms_sql FROM @cascade ORDER BY id;',\n 'END',\n \"EXEC sp_executesql N'DROP SCHEMA\", this.quoteIdentifier(schema), \";'\",\n 'END;'\n ].join(' ');\n }\n\n showSchemasQuery() {\n return [\n 'SELECT \"name\" as \"schema_name\" FROM sys.schemas as s',\n 'WHERE \"s\".\"name\" NOT IN (',\n \"'INFORMATION_SCHEMA', 'dbo', 'guest', 'sys', 'archive'\",\n ')', 'AND', '\"s\".\"name\" NOT LIKE', \"'db_%'\"\n ].join(' ');\n }\n\n versionQuery() {\n // Uses string manipulation to convert the MS Maj.Min.Patch.Build to semver Maj.Min.Patch\n return [\n 'DECLARE @ms_ver NVARCHAR(20);',\n \"SET @ms_ver = REVERSE(CONVERT(NVARCHAR(20), SERVERPROPERTY('ProductVersion')));\",\n \"SELECT REVERSE(SUBSTRING(@ms_ver, CHARINDEX('.', @ms_ver)+1, 20)) AS 'version'\"\n ].join(' ');\n }\n\n createTableQuery(tableName, attributes, options) {\n const primaryKeys = [],\n foreignKeys = {},\n attributesClauseParts = [];\n\n let commentS
|
||
|
"mappings": ";;;;;;;;;;;;;;;;;AAEA,MAAM,IAAI,QAAQ;AAClB,MAAM,QAAQ,QAAQ;AACtB,MAAM,YAAY,QAAQ;AAC1B,MAAM,aAAa,QAAQ;AAC3B,MAAM,yBAAyB,QAAQ;AACvC,MAAM,cAAc,QAAQ,UAAU;AACtC,MAAM,SAAS,QAAQ;AACvB,MAAM,KAAK,QAAQ;AAGnB,MAAM,uBAAuB,SAAS,YAAY;AAChD,QAAM,IAAI,MAAM,eAAe;AAAA;AAGjC,kCAAkC,uBAAuB;AAAA,EACvD,oBAAoB,cAAc,SAAS;AACzC,cAAU,iBAAE,SAAS,QAAS;AAE9B,UAAM,YAAY,QAAQ,UAAU,WAAW,KAAK,OAAO,QAAQ,aAAa;AAEhF,WAAO;AAAA,MACL;AAAA,MAA2D,gBAAgB;AAAA,MAAe;AAAA,MAC1F;AAAA,MACA;AAAA,MAAmB,KAAK,gBAAgB;AAAA,MACxC,GAAG;AAAA,MACH;AAAA,MACA,KAAK;AAAA;AAAA,EAGT,kBAAkB,cAAc;AAC9B,WAAO;AAAA,MACL;AAAA,MAAuD,gBAAgB;AAAA,MAAe;AAAA,MACtF;AAAA,MACA;AAAA,MAAiB,KAAK,gBAAgB;AAAA,MAAe;AAAA,MACrD;AAAA,MACA,KAAK;AAAA;AAAA,EAGT,aAAa,QAAQ;AACnB,WAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MAAuB,gBAAgB;AAAA,MAAS;AAAA,MAChD;AAAA,MACA;AAAA,MACA,KAAK,gBAAgB;AAAA,MACrB;AAAA,MACA;AAAA,MACA,KAAK;AAAA;AAAA,EAGT,WAAW,QAAQ;AAEjB,UAAM,eAAe,gBAAgB;AACrC,WAAO;AAAA,MACL;AAAA,M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