Skip to main content
Module

x/typeorm/src/index.ts>QueryRunner

Forked from https://github.com/typeorm/typeorm
Latest
interface QueryRunner
Re-export
import { type QueryRunner } from "https://deno.land/x/typeorm@v0.2.23-rc10/src/index.ts";

Runs queries on a single database connection.

Properties

readonly
connection: Connection

Connection used by this query runner.

readonly
broadcaster: Broadcaster

Broadcaster used on this query runner to broadcast entity events.

readonly
manager: EntityManager

Entity manager working only with this query runner.

readonly
isReleased: boolean

Indicates if connection for this query runner is released. Once its released, query runner cannot run queries anymore.

readonly
isTransactionActive: boolean

Indicates if transaction is in progress.

data: ObjectLiteral

Stores temporarily user data. Useful for sharing data with subscribers.

loadedTables: Table[]

All synchronized tables in the database.

loadedViews: View[]

All synchronized views in the database.

Methods

connect(): Promise<any>

Creates/uses database connection from the connection pool to perform further operations. Returns obtained database connection.

release(): Promise<void>

Releases used database connection. You cannot use query runner methods after connection is released.

clearDatabase(database?: string): Promise<void>

Removes all tables from the currently connected database. Be careful with using this method and avoid using it in production or migrations (because it can clear all your database).

startTransaction(isolationLevel?: IsolationLevel): Promise<void>

Starts transaction.

commitTransaction(): Promise<void>

Commits transaction. Error will be thrown if transaction was not started.

rollbackTransaction(): Promise<void>

Ends transaction. Error will be thrown if transaction was not started.

query(query: string, parameters?: any[]): Promise<any>

Executes a given SQL query and returns raw database results.

stream(
query: string,
parameters?: any[],
onEnd?: Function,
onError?: Function,
): Promise<ReadStream>

Returns raw data stream.

getDatabases(): Promise<string[]>

Returns all available database names including system databases.

getSchemas(database?: string): Promise<string[]>

Returns all available schema names including system schemas. If database parameter specified, returns schemas of that database. Useful for SQLServer and Postgres only.

getTable(tablePath: string): Promise<Table | undefined>

Loads a table by a given name from the database.

getTables(tablePaths: string[]): Promise<Table[]>

Loads all tables from the database and returns them.

todo: make tablePaths optional

getView(viewPath: string): Promise<View | undefined>

Loads a view by a given name from the database.

getViews(viewPaths: string[]): Promise<View[]>

Loads all views from the database and returns them.

hasDatabase(database: string): Promise<boolean>

Checks if a database with the given name exist.

hasSchema(schema: string): Promise<boolean>

Checks if a schema with the given name exist.

hasTable(table: Table | string): Promise<boolean>

Checks if a table with the given name exist.

hasColumn(table: Table | string, columnName: string): Promise<boolean>

Checks if a column exist in the table.

createDatabase(database: string, ifNotExist?: boolean): Promise<void>

Creates a new database.

dropDatabase(database: string, ifExist?: boolean): Promise<void>

Drops database.

createSchema(schemaPath: string, ifNotExist?: boolean): Promise<void>

Creates a new table schema.

dropSchema(
schemaPath: string,
ifExist?: boolean,
isCascade?: boolean,
): Promise<void>

Drops table schema. For SqlServer can accept schema path (e.g. 'dbName.schemaName') as parameter. If schema path passed, it will drop schema in specified database.

createTable(
table: Table,
ifNotExist?: boolean,
createForeignKeys?: boolean,
createIndices?: boolean,
): Promise<void>

Creates a new table.

dropTable(
table: Table | string,
ifExist?: boolean,
dropForeignKeys?: boolean,
dropIndices?: boolean,
): Promise<void>

Drops a table.

createView(view: View, oldView?: View): Promise<void>

Creates a new view.

dropView(view: View | string): Promise<void>

Drops a view.

renameTable(oldTableOrName: Table | string, newTableName: string): Promise<void>

Renames a table.

addColumn(table: Table | string, column: TableColumn): Promise<void>

Adds a new column.

addColumns(table: Table | string, columns: TableColumn[]): Promise<void>

Adds new columns.

renameColumn(
table: Table | string,
oldColumnOrName: TableColumn | string,
newColumnOrName: TableColumn | string,
): Promise<void>

Renames a column.

changeColumn(
table: Table | string,
oldColumn: TableColumn | string,
newColumn: TableColumn,
): Promise<void>

Changes a column in the table.

changeColumns(table: Table | string, changedColumns: { oldColumn: TableColumn; newColumn: TableColumn; }[]): Promise<void>

Changes columns in the table.

dropColumn(table: Table | string, column: TableColumn | string): Promise<void>

Drops a column in the table.

dropColumns(table: Table | string, columns: TableColumn[]): Promise<void>

Drops columns in the table.

createPrimaryKey(table: Table | string, columnNames: string[]): Promise<void>

Creates a new primary key.

updatePrimaryKeys(table: Table | string, columns: TableColumn[]): Promise<void>

Updates composite primary keys.

dropPrimaryKey(table: Table | string): Promise<void>

Drops a primary key.

createUniqueConstraint(table: Table | string, uniqueConstraint: TableUnique): Promise<void>

Creates a new unique constraint.

createUniqueConstraints(table: Table | string, uniqueConstraints: TableUnique[]): Promise<void>

Creates new unique constraints.

dropUniqueConstraint(table: Table | string, uniqueOrName: TableUnique | string): Promise<void>

Drops an unique constraint.

dropUniqueConstraints(table: Table | string, uniqueConstraints: TableUnique[]): Promise<void>

Drops unique constraints.

createCheckConstraint(table: Table | string, checkConstraint: TableCheck): Promise<void>

Creates a new check constraint.

createCheckConstraints(table: Table | string, checkConstraints: TableCheck[]): Promise<void>

Creates new check constraints.

dropCheckConstraint(table: Table | string, checkOrName: TableCheck | string): Promise<void>

Drops a check constraint.

dropCheckConstraints(table: Table | string, checkConstraints: TableCheck[]): Promise<void>

Drops check constraints.

createExclusionConstraint(table: Table | string, exclusionConstraint: TableExclusion): Promise<void>

Creates a new exclusion constraint.

createExclusionConstraints(table: Table | string, exclusionConstraints: TableExclusion[]): Promise<void>

Creates new exclusion constraints.

dropExclusionConstraint(table: Table | string, exclusionOrName: TableExclusion | string): Promise<void>

Drops a exclusion constraint.

dropExclusionConstraints(table: Table | string, exclusionConstraints: TableExclusion[]): Promise<void>

Drops exclusion constraints.

createForeignKey(table: Table | string, foreignKey: TableForeignKey): Promise<void>

Creates a new foreign key.

createForeignKeys(table: Table | string, foreignKeys: TableForeignKey[]): Promise<void>

Creates new foreign keys.

dropForeignKey(table: Table | string, foreignKeyOrName: TableForeignKey | string): Promise<void>

Drops a foreign key.

dropForeignKeys(table: Table | string, foreignKeys: TableForeignKey[]): Promise<void>

Drops foreign keys.

createIndex(table: Table | string, index: TableIndex): Promise<void>

Creates a new index.

createIndices(table: Table | string, indices: TableIndex[]): Promise<void>

Creates new indices.

dropIndex(table: Table | string, index: TableIndex | string): Promise<void>

Drops an index.

dropIndices(table: Table | string, indices: TableIndex[]): Promise<void>

Drops indices.

clearTable(tableName: string): Promise<void>

Clears all table contents. Note: this operation uses SQL's TRUNCATE query which cannot be reverted in transactions.

enableSqlMemory(): void

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.

disableSqlMemory(): 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.

clearSqlMemory(): void

Flushes all memorized sqls.

getMemorySql(): SqlInMemory

Gets sql stored in the memory. Parameters in the sql are already replaced.

executeMemoryUpSql(): Promise<void>

Executes up sql queries.

executeMemoryDownSql(): Promise<void>

Executes down sql queries.