import { QueryRunner } from "../../query-runner/QueryRunner"; import { ObjectLiteral } from "../../common/ObjectLiteral"; import { ColumnSchema } from "../../schema-builder/schema/ColumnSchema"; import { TableSchema } from "../../schema-builder/schema/TableSchema"; import { ForeignKeySchema } from "../../schema-builder/schema/ForeignKeySchema"; import { IndexSchema } from "../../schema-builder/schema/IndexSchema"; import { SqlServerDriver } from "./SqlServerDriver"; import { Connection } from "../../connection/Connection"; import { ReadStream } from "../../platform/PlatformTools"; import { MssqlParameter } from "./MssqlParameter"; import { EntityManager } from "../../entity-manager/EntityManager"; /** * Runs queries on a single mysql database connection. */ export declare class SqlServerQueryRunner implements QueryRunner { /** * Database driver used by connection. */ driver: SqlServerDriver; /** * Connection used by this query runner. */ connection: Connection; /** * Isolated entity manager working only with current query runner. */ manager: EntityManager; /** * Indicates if connection for this query runner is released. * Once its released, query runner cannot run queries anymore. */ isReleased: boolean; /** * Indicates if transaction is in progress. */ isTransactionActive: boolean; /** * Stores temporarily user data. * Useful for sharing data with subscribers. */ data: {}; /** * Real database connection from a connection pool used to perform queries. */ protected databaseConnection: any; /** * Last executed query in a transaction. * This is needed because in transaction mode mssql cannot execute parallel queries, * that's why we store last executed query promise to wait it when we execute next query. * * @see https://github.com/patriksimek/node-mssql/issues/491 */ protected queryResponsibilityChain: Promise[]; /** * Indicates if special query runner mode in which sql queries won't be executed is enabled. */ protected sqlMemoryMode: boolean; /** * Sql-s stored if "sql in memory" mode is enabled. */ protected sqlsInMemory: string[]; /** * Mode in which query runner executes. * Used for replication. * If replication is not setup its value is ignored. */ protected mode: "master" | "slave"; constructor(driver: SqlServerDriver, mode?: "master" | "slave"); /** * Creates/uses database connection from the connection pool to perform further operations. * Returns obtained database connection. */ connect(): Promise; /** * Releases used database connection. * You cannot use query runner methods once its released. */ release(): Promise; /** * Starts transaction. */ startTransaction(): Promise; /** * Commits transaction. * Error will be thrown if transaction was not started. */ commitTransaction(): Promise; /** * Rollbacks transaction. * Error will be thrown if transaction was not started. */ rollbackTransaction(): Promise; protected mssqlParameterToNativeParameter(parameter: MssqlParameter): any; /** * Executes a given SQL query. */ query(query: string, parameters?: any[]): Promise; /** * Returns raw data stream. */ stream(query: string, parameters?: any[], onEnd?: Function, onError?: Function): Promise; /** * Insert a new row with given values into the given table. * Returns value of the generated column if given and generate column exist in the table. */ insert(tableName: string, keyValues: ObjectLiteral): Promise; /** * Updates rows that match given conditions in the given table. */ update(tableName: string, valuesMap: ObjectLiteral, conditions: ObjectLiteral): Promise; /** * Deletes from the given table by a given conditions. */ delete(tableName: string, conditions: ObjectLiteral | string, maybeParameters?: any[]): Promise; /** * Inserts rows into the closure table. */ insertIntoClosureTable(tableName: string, newEntityId: any, parentId: any, hasLevel: boolean): Promise; /** * Loads given table's data from the database. */ loadTableSchema(tableName: string): Promise; /** * Loads all tables (with given names) from the database and creates a TableSchema from them. */ loadTableSchemas(tableNames: string[]): Promise; /** * Checks if table with the given name exist in the database. */ hasTable(tableName: string): Promise; /** * Creates a schema if it's not created. */ createSchema(): Promise; /** * Creates a new table from the given table metadata and column metadatas. */ createTable(table: TableSchema): Promise; /** * Drops the table. */ dropTable(tableName: string): Promise; /** * Checks if column with the given name exist in the given table. */ hasColumn(tableName: string, columnName: string): Promise; /** * Creates a new column from the column schema in the table. */ addColumn(tableSchemaOrName: TableSchema | string, column: ColumnSchema): Promise; /** * Creates a new columns from the column schema in the table. */ addColumns(tableSchemaOrName: TableSchema | string, columns: ColumnSchema[]): Promise; /** * Renames column in the given table. */ renameColumn(tableSchemaOrName: TableSchema | string, oldColumnSchemaOrName: ColumnSchema | string, newColumnSchemaOrName: ColumnSchema | string): Promise; /** * Changes a column in the table. */ changeColumn(tableSchemaOrName: TableSchema | string, oldColumnSchemaOrName: ColumnSchema | string, newColumn: ColumnSchema): Promise; /** * Changes a column in the table. */ changeColumns(tableSchema: TableSchema, changedColumns: { newColumn: ColumnSchema; oldColumn: ColumnSchema; }[]): Promise; /** * Drops column in the table. */ dropColumn(table: TableSchema, column: ColumnSchema): Promise; /** * Drops the columns in the table. */ dropColumns(table: TableSchema, columns: ColumnSchema[]): Promise; /** * Updates table's primary keys. */ updatePrimaryKeys(dbTable: TableSchema): Promise; /** * Creates a new foreign key. */ createForeignKey(tableSchemaOrName: TableSchema | string, foreignKey: ForeignKeySchema): Promise; /** * Creates a new foreign keys. */ createForeignKeys(tableSchemaOrName: TableSchema | string, foreignKeys: ForeignKeySchema[]): Promise; /** * Drops a foreign key from the table. */ dropForeignKey(tableSchemaOrName: TableSchema | string, foreignKey: ForeignKeySchema): Promise; /** * Drops a foreign keys from the table. */ dropForeignKeys(tableSchemaOrName: TableSchema | string, foreignKeys: ForeignKeySchema[]): Promise; /** * Creates a new index. */ createIndex(tableName: string, index: IndexSchema): Promise; /** * Drops an index from the table. */ dropIndex(tableName: string, indexName: string): Promise; /** * Truncates table. */ truncate(tableName: string): Promise; /** * Removes all tables from the currently connected database. */ clearDatabase(): Promise; /** * Enables special query runner mode in which sql queries won't be executed, * instead they will be memorized into a special variable inside query runner. * You can get memorized sql using getMemorySql() method. */ enableSqlMemory(): void; /** * Disables special query runner mode in which sql queries won't be executed * started by calling enableSqlMemory() method. * * Previously memorized sql will be flushed. */ disableSqlMemory(): void; /** * Gets sql stored in the memory. Parameters in the sql are already replaced. */ getMemorySql(): (string | { up: string; down: string; })[]; /** * Database name shortcut. */ protected readonly dbName: string; /** * Parametrizes given object of values. Used to create column=value queries. */ protected parametrize(objectLiteral: ObjectLiteral, startFrom?: number): string[]; /** * Builds a query for create column. */ protected buildCreateColumnSql(tableName: string, column: ColumnSchema, skipIdentity: boolean, createDefault: boolean): string; }