You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

8 lines
44 KiB

{
"version": 3,
"sources": ["../../../src/dialects/db2/query-generator.js"],
"sourcesContent": ["'use strict';\n\nconst _ = require('lodash');\nconst Utils = require('../../utils');\nconst DataTypes = require('../../data-types');\nconst AbstractQueryGenerator = require('../abstract/query-generator');\nconst randomBytes = require('crypto').randomBytes;\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 Db2QueryGenerator extends AbstractQueryGenerator {\n constructor(options) {\n super(options);\n\n this.OperatorMap = { ...this.OperatorMap, [Op.regexp]: 'REGEXP_LIKE',\n [Op.notRegexp]: 'NOT REGEXP_LIKE' };\n this.autoGenValue = 1;\n }\n\n createSchema(schema) {\n return [\n 'CREATE SCHEMA',\n this.quoteIdentifier(schema),\n ';'\n ].join(' ');\n }\n\n dropSchema(schema) {\n // DROP SCHEMA Can't drop schema if it is not empty.\n // DROP SCHEMA Can't drop objects belonging to the schema\n // So, call the admin procedure to drop schema.\n const query = `CALL SYSPROC.ADMIN_DROP_SCHEMA(${ wrapSingleQuote(schema.trim()) }, NULL, ? , ?)`;\n const sql = { query };\n sql.bind = [{ ParamType: 'INOUT', Data: 'ERRORSCHEMA' },\n { ParamType: 'INOUT', Data: 'ERRORTABLE' }];\n return sql;\n }\n\n showSchemasQuery() {\n return 'SELECT SCHEMANAME AS \"schema_name\" FROM SYSCAT.SCHEMATA WHERE ' +\n \"(SCHEMANAME NOT LIKE 'SYS%') AND SCHEMANAME NOT IN ('NULLID', 'SQLJ', 'ERRORSCHEMA')\";\n }\n\n\n\n versionQuery() {\n return 'select service_level as VERSION from TABLE (sysproc.env_get_inst_info()) as A';\n }\n\n createTableQuery(tableName, attributes, options) {\n const query = 'CREATE TABLE <%= table %> (<%= attributes %>)',\n primaryKeys = [],\n foreignKeys = {},\n attrStr = [],\n commentTemplate = ' -- <%= comment %>, ' +\n 'TableName = <%= table %>, ColumnName = <%= column %>;';\n\n let commentStr = '';\n\n for (const attr in attributes) {\n if (Object.prototype.hasOwnProperty.call(attributes, attr)) {\n let dataType = attributes[attr];\n let match;\n\n if (dataType.includes('COMMENT ')) {\n const commentMatch = dataType.match(/^(.+) (COMMENT.*)$/);\n if (commentMatch && commentMatch.length > 2) {\n const commentText = commentMatch[2].replace(/COMMENT/, '').trim();\n commentStr += _.template(commentTemplate, this._templateSettings)({\n table: this.quoteIdentifier(tableName),\n comment: this.escape(commentText),\n column: this.quoteIdentifier(attr)\n });\n // remove comment related substring from dataType\n dataType = commentMatch[1];\n }\n }\n\n if (_.includes(dataType, 'PRIMARY KEY')) {\n primaryKeys.push(attr);\n\n if (_.includes(dataType, 'REFERENCES')) {\n // Db2 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 (_.includes(dataType, 'REFERENCES')) {\n // Db2 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 if (options && options.uniqueKeys) {\n for (const ukey in options.uniqueKeys) {\n if (options.uniqueKeys[ukey].fields.includes(attr) &&\n ! _.includes(dataType, 'NOT NULL'))\n {\n dataType += ' NOT NULL';\n break;\n }\n
"mappings": ";;;;;;;;;;;;;;;;;;;;AAEA,MAAM,IAAI,QAAQ;AAClB,MAAM,QAAQ,QAAQ;AACtB,MAAM,YAAY,QAAQ;AAC1B,MAAM,yBAAyB,QAAQ;AACvC,MAAM,cAAc,QAAQ,UAAU;AACtC,MAAM,KAAK,QAA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