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
32 KiB

{
"version": 3,
"sources": ["../../../src/dialects/snowflake/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\n/**\n * list of reserved words in Snowflake\n * source: https://docs.snowflake.com/en/sql-reference/reserved-keywords.html\n *\n * @private\n */\nconst SNOWFLAKE_RESERVED_WORDS = 'account,all,alter,and,any,as,between,by,case,cast,check,column,connect,connections,constraint,create,cross,current,current_date,current_time,current_timestamp,current_user,database,delete,distinct,drop,else,exists,false,following,for,from,full,grant,group,gscluster,having,ilike,in,increment,inner,insert,intersect,into,is,issue,join,lateral,left,like,localtime,localtimestamp,minus,natural,not,null,of,on,or,order,organization,qualify,regexp,revoke,right,rlike,row,rows,sample,schema,select,set,some,start,table,tablesample,then,to,trigger,true,try_cast,union,unique,update,using,values,view,when,whenever,where,with'.split(',');\n\nconst typeWithoutDefault = new Set(['BLOB', 'TEXT', 'GEOMETRY', 'JSON']);\n\nclass SnowflakeQueryGenerator 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 CURRENT_VERSION()';\n }\n\n createTableQuery(tableName, attributes, options) {\n options = {\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 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 match = dataType.match(/^(.+) (REFERENCES.*)$/);\n attrStr.push(`${this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