Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface QueryRunner

Runs queries on a single database connection.

Hierarchy

  • QueryRunner

Implemented by

Index

Properties

broadcaster

broadcaster: Broadcaster

Broadcaster used on this query runner to broadcast entity events.

connection

connection: Connection

Connection used by this query runner.

data

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

isReleased

isReleased: boolean

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

isTransactionActive

isTransactionActive: boolean

Indicates if transaction is in progress.

loadedTables

loadedTables: Table[]

All synchronized tables in the database.

loadedViews

loadedViews: View[]

All synchronized views in the database.

manager

manager: EntityManager

Entity manager working only with this query runner.

Methods

addColumn

addColumns

changeColumn

changeColumns

  • changeColumns(table: Table | string, changedColumns: object[]): Promise<void>

clearDatabase

  • 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).

    Parameters

    • Optional database: string

    Returns Promise<void>

clearSqlMemory

  • clearSqlMemory(): void

clearTable

  • clearTable(tableName: string): Promise<void>
  • Clears all table contents. Note: this operation uses SQL's TRUNCATE query which cannot be reverted in transactions.

    Parameters

    • tableName: string

    Returns Promise<void>

commitTransaction

  • commitTransaction(): Promise<void>

connect

  • connect(): Promise<any>
  • Creates/uses database connection from the connection pool to perform further operations. Returns obtained database connection.

    Returns Promise<any>

createCheckConstraint

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

createCheckConstraints

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

createDatabase

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

createExclusionConstraint

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

createExclusionConstraints

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

createForeignKey

createForeignKeys

createIndex

createIndices

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

createPrimaryKey

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

createSchema

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

createTable

  • createTable(table: Table, ifNotExist?: boolean, createForeignKeys?: boolean, createIndices?: boolean): Promise<void>
  • Creates a new table.

    Parameters

    • table: Table
    • Optional ifNotExist: boolean
    • Optional createForeignKeys: boolean
    • Optional createIndices: boolean

    Returns Promise<void>

createUniqueConstraint

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

createUniqueConstraints

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

createView

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

disableSqlMemory

  • 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.

    Returns void

dropCheckConstraint

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

dropCheckConstraints

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

dropColumn

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

dropColumns

dropDatabase

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

dropExclusionConstraint

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

dropExclusionConstraints

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

dropForeignKey

dropForeignKeys

dropIndex

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

dropIndices

dropPrimaryKey

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

dropSchema

  • 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.

    Parameters

    • schemaPath: string
    • Optional ifExist: boolean
    • Optional isCascade: boolean

    Returns Promise<void>

dropTable

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

    Parameters

    • table: Table | string
    • Optional ifExist: boolean
    • Optional dropForeignKeys: boolean
    • Optional dropIndices: boolean

    Returns Promise<void>

dropUniqueConstraint

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

dropUniqueConstraints

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

dropView

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

enableSqlMemory

  • 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.

    Returns void

executeMemoryDownSql

  • executeMemoryDownSql(): Promise<void>

executeMemoryUpSql

  • executeMemoryUpSql(): Promise<void>

getDatabases

  • getDatabases(): Promise<string[]>

getMemorySql

getSchemas

  • 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.

    Parameters

    • Optional database: string

    Returns Promise<string[]>

getTable

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

getTables

  • getTables(tablePaths: string[]): Promise<Table[]>
  • Loads all tables from the database and returns them.

    todo: make tablePaths optional

    Parameters

    • tablePaths: string[]

    Returns Promise<Table[]>

getView

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

getViews

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

hasColumn

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

hasDatabase

  • hasDatabase(database: string): Promise<boolean>

hasSchema

  • hasSchema(schema: string): Promise<boolean>

hasTable

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

query

  • query(query: string, parameters?: any[]): Promise<any>
  • Executes a given SQL query and returns raw database results.

    Parameters

    • query: string
    • Optional parameters: any[]

    Returns Promise<any>

release

  • release(): Promise<void>
  • Releases used database connection. You cannot use query runner methods after connection is released.

    Returns Promise<void>

renameColumn

renameTable

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

rollbackTransaction

  • rollbackTransaction(): Promise<void>

startTransaction

stream

  • stream(query: string, parameters?: any[], onEnd?: Function, onError?: Function): Promise<ReadStream>
  • Returns raw data stream.

    Parameters

    • query: string
    • Optional parameters: any[]
    • Optional onEnd: Function
    • Optional onError: Function

    Returns Promise<ReadStream>

updatePrimaryKeys

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

Generated using TypeDoc