Options
All
  • Public
  • Public/Protected
  • All
Menu

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.

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?: undefined | 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: undefined | 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?: undefined | true | false): Promise<void>
  • Creates a new database.

    Parameters

    • database: string
    • Optional ifNotExist: undefined | true | false

    Returns 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?: undefined | true | false): Promise<void>
  • Creates a new table schema.

    Parameters

    • schemaPath: string
    • Optional ifNotExist: undefined | true | false

    Returns Promise<void>

createTable

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

    Parameters

    • table: Table
    • Optional ifNotExist: undefined | true | false
    • Optional createForeignKeys: undefined | true | false
    • Optional createIndices: undefined | true | false

    Returns Promise<void>

createUniqueConstraint

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

createUniqueConstraints

  • createUniqueConstraints(table: Table | string, uniqueConstraints: TableUnique[]): 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?: undefined | true | false): 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?: undefined | true | false, isCascade?: undefined | true | false): 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: undefined | true | false
    • Optional isCascade: undefined | true | false

    Returns Promise<void>

dropTable

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

    Parameters

    • table: Table | string
    • Optional ifExist: undefined | true | false
    • Optional dropForeignKeys: undefined | true | false
    • Optional dropIndices: undefined | true | false

    Returns Promise<void>

dropUniqueConstraint

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

dropUniqueConstraints

  • dropUniqueConstraints(table: Table | string, uniqueConstraints: TableUnique[]): 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?: undefined | 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: undefined | string

    Returns Promise<string[]>

getTable

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

getTables

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

    todo: make tableNames optional

    Parameters

    • tableNames: string[]

    Returns Promise<Table[]>

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