/var/www/greso.tech/server/nsm/node_modules/sequelize/lib/dialects/abstract
Edit: /var/www/greso.tech/server/nsm/node_modules/sequelize/lib/dialects/abstract/query-interface.js.map (57015B)
{
"version": 3,
"sources": ["../../../src/dialects/abstract/query-interface.js"],
"sourcesContent": ["'use strict';\n\nconst _ = require('lodash');\n\nconst Utils = require('../../utils');\nconst DataTypes = require('../../data-types');\nconst Transaction = require('../../transaction');\nconst QueryTypes = require('../../query-types');\n\n/**\n * The interface that Sequelize uses to talk to all databases\n */\nclass QueryInterface {\n constructor(sequelize, queryGenerator) {\n this.sequelize = sequelize;\n this.queryGenerator = queryGenerator;\n }\n\n /**\n * Create a database\n *\n * @param {string} database Database name to create\n * @param {object} [options] Query options\n * @param {string} [options.charset] Database default character set, MYSQL only\n * @param {string} [options.collate] Database default collation\n * @param {string} [options.encoding] Database default character set, PostgreSQL only\n * @param {string} [options.ctype] Database character classification, PostgreSQL only\n * @param {string} [options.template] The name of the template from which to create the new database, PostgreSQL only\n *\n * @returns {Promise}\n */\n async createDatabase(database, options) {\n options = options || {};\n const sql = this.queryGenerator.createDatabaseQuery(database, options);\n return await this.sequelize.query(sql, options);\n }\n\n /**\n * Drop a database\n *\n * @param {string} database Database name to drop\n * @param {object} [options] Query options\n *\n * @returns {Promise}\n */\n async dropDatabase(database, options) {\n options = options || {};\n const sql = this.queryGenerator.dropDatabaseQuery(database);\n return await this.sequelize.query(sql, options);\n }\n\n /**\n * Create a schema\n *\n * @param {string} schema Schema name to create\n * @param {object} [options] Query options\n *\n * @returns {Promise}\n */\n async createSchema(schema, options) {\n options = options || {};\n const sql = this.queryGenerator.createSchema(schema);\n return await this.sequelize.query(sql, options);\n }\n\n /**\n * Drop a schema\n *\n * @param {string} schema Schema name to drop\n * @param {object} [options] Query options\n *\n * @returns {Promise}\n */\n async dropSchema(schema, options) {\n options = options || {};\n const sql = this.queryGenerator.dropSchema(schema);\n return await this.sequelize.query(sql, options);\n }\n\n /**\n * Drop all schemas\n *\n * @param {object} [options] Query options\n *\n * @returns {Promise}\n */\n async dropAllSchemas(options) {\n options = options || {};\n\n if (!this.queryGenerator._dialect.supports.schemas) {\n return this.sequelize.drop(options);\n }\n const schemas = await this.showAllSchemas(options);\n return Promise.all(schemas.map(schemaName => this.dropSchema(schemaName, options)));\n }\n\n /**\n * Show all schemas\n *\n * @param {object} [options] Query options\n *\n * @returns {Promise
}\n */\n async showAllSchemas(options) {\n options = {\n ...options,\n raw: true,\n type: this.sequelize.QueryTypes.SELECT\n };\n\n const showSchemasSql = this.queryGenerator.showSchemasQuery(options);\n\n const schemaNames = await this.sequelize.query(showSchemasSql, options);\n\n return _.flatten(schemaNames.map(value => value.schema_name ? value.schema_name : value));\n }\n\n /**\n * Return database version\n *\n * @param {object} [options] Query options\n * @param {QueryType} [options.type] Query type\n *\n * @returns {Promise}\n * @private\n */\n async databaseVersion(options) {\n return await this.sequelize.query(\n this.queryGenerator.versionQuery(),\n { ...options, type: QueryTypes.VERSION }\n );\n }\n\n /**\n * Create a table with given set of attributes\n *\n * ```js\n * queryInterface.createTable(\n * 'nameOfTheNewTable',\n * {\n * id: {\n * type: Sequelize.INTEGER,\n * primaryKey: true,\n * autoIncrement: true\n * },\n * createdAt: {\n * type: Sequelize.DATE\n * },\n * updatedAt: {\n * type: Sequelize.DATE\n * },\n * attr1: Sequelize.STRING,\n * attr2: Sequelize.INTEGER,\n * attr3: {\n * type: Sequelize.BOOLEAN,\n * defaultValue: false,\n * allowNull: false\n * },\n * //foreign key usage\n * attr4: {\n * type: Sequelize.INTEGER,\n * references: {\n * model: 'another_table_name',\n * key: 'id'\n * },\n * onUpdate: 'cascade',\n * onDelete: 'cascade'\n * }\n * },\n * {\n * engine: 'MYISAM', // default: 'InnoDB'\n * charset: 'latin1', // default: null\n * schema: 'public', // default: public, PostgreSQL only.\n * comment: 'my table', // comment for table\n * collate: 'latin1_danish_ci' // collation, MYSQL only\n * }\n * )\n * ```\n *\n * @param {string} tableName Name of table to create\n * @param {object} attributes Object representing a list of table attributes to create\n * @param {object} [options] create table and query options\n * @param {Model} [model] model class\n *\n * @returns {Promise}\n */\n async createTable(tableName, attributes, options, model) {\n let sql = '';\n\n options = { ...options };\n\n if (options && options.uniqueKeys) {\n _.forOwn(options.uniqueKeys, uniqueKey => {\n if (uniqueKey.customIndex === undefined) {\n uniqueKey.customIndex = true;\n }\n });\n }\n\n if (model) {\n options.uniqueKeys = options.uniqueKeys || model.uniqueKeys;\n }\n\n attributes = _.mapValues(\n attributes,\n attribute => this.sequelize.normalizeAttribute(attribute)\n );\n\n // Postgres requires special SQL commands for ENUM/ENUM[]\n await this.ensureEnums(tableName, attributes, options, model);\n\n if (\n !tableName.schema &&\n (options.schema || !!model && model._schema)\n ) {\n tableName = this.queryGenerator.addSchema({\n tableName,\n _schema: !!model && model._schema || options.schema\n });\n }\n\n attributes = this.queryGenerator.attributesToSQL(attributes, {\n table: tableName,\n context: 'createTable',\n withoutForeignKeyConstraints: options.withoutForeignKeyConstraints\n });\n sql = this.queryGenerator.createTableQuery(tableName, attributes, options);\n\n return await this.sequelize.query(sql, options);\n }\n\n /**\n * Returns a promise that will resolve to true if the table exists in the database, false otherwise.\n *\n * @param {TableName} tableName - The name of the table\n * @param {QueryOptions} options - Query options\n * @returns {Promise}\n */\n async tableExists(tableName, options) {\n const sql = this.queryGenerator.tableExistsQuery(tableName);\n\n const out = await this.sequelize.query(sql, {\n ...options,\n type: QueryTypes.SHOWTABLES\n });\n\n return out.length === 1;\n }\n\n /**\n * Drop a table from database\n *\n * @param {string} tableName Table name to drop\n * @param {object} options Query options\n *\n * @returns {Promise}\n */\n async dropTable(tableName, options) {\n // if we're forcing we should be cascading unless explicitly stated otherwise\n options = { ...options };\n options.cascade = options.cascade || options.force || false;\n\n const sql = this.queryGenerator.dropTableQuery(tableName, options);\n\n await this.sequelize.query(sql, options);\n }\n\n async _dropAllTables(tableNames, skip, options) {\n for (const tableName of tableNames) {\n // if tableName is not in the Array of tables names then don't drop it\n if (!skip.includes(tableName.tableName || tableName)) {\n await this.dropTable(tableName, { ...options, cascade: true } );\n }\n }\n }\n\n /**\n * Drop all tables from database\n *\n * @param {object} [options] query options\n * @param {Array} [options.skip] List of table to skip\n *\n * @returns {Promise}\n */\n async dropAllTables(options) {\n options = options || {};\n const skip = options.skip || [];\n\n const tableNames = await this.showAllTables(options);\n const foreignKeys = await this.getForeignKeysForTables(tableNames, options);\n\n for (const tableName of tableNames) {\n let normalizedTableName = tableName;\n if (_.isObject(tableName)) {\n normalizedTableName = `${tableName.schema}.${tableName.tableName}`;\n }\n\n for (const foreignKey of foreignKeys[normalizedTableName]) {\n await this.sequelize.query(this.queryGenerator.dropForeignKeyQuery(tableName, foreignKey));\n }\n }\n await this._dropAllTables(tableNames, skip, options);\n }\n\n /**\n * Rename a table\n *\n * @param {string} before Current name of table\n * @param {string} after New name from table\n * @param {object} [options] Query options\n *\n * @returns {Promise}\n */\n async renameTable(before, after, options) {\n options = options || {};\n const sql = this.queryGenerator.renameTableQuery(before, after);\n return await this.sequelize.query(sql, options);\n }\n\n /**\n * Get all tables in current database\n *\n * @param {object} [options] Query options\n * @param {boolean} [options.raw=true] Run query in raw mode\n * @param {QueryType} [options.type=QueryType.SHOWTABLE] query type\n *\n * @returns {Promise}\n * @private\n */\n async showAllTables(options) {\n options = {\n ...options,\n raw: true,\n type: QueryTypes.SHOWTABLES\n };\n\n const showTablesSql = this.queryGenerator.showTablesQuery(this.sequelize.config.database);\n const tableNames = await this.sequelize.query(showTablesSql, options);\n return _.flatten(tableNames);\n }\n\n /**\n * Describe a table structure\n *\n * This method returns an array of hashes containing information about all attributes in the table.\n *\n * ```js\n * {\n * name: {\n * type: 'VARCHAR(255)', // this will be 'CHARACTER VARYING' for pg!\n * allowNull: true,\n * defaultValue: null\n * },\n * isBetaMember: {\n * type: 'TINYINT(1)', // this will be 'BOOLEAN' for pg!\n * allowNull: false,\n * defaultValue: false\n * }\n * }\n * ```\n *\n * @param {string} tableName table name\n * @param {object} [options] Query options\n *\n * @returns {Promise