Skip to main content
Version: 7.2

abstractConnection

Abstract base class for database connections, providing transaction and query execution support.

Hierarchy

Index

Constructors

constructor

Methods

begin

  • begin(options): Promise<any>
  • Begins a new database transaction and returns the transaction context.


    Parameters

    Returns Promise<any>

abstractcheckConnection

  • checkConnection(): Promise<{ ok: true } | { error?: Error; ok: false; reason: string }>
  • Are we connected to the database


    Returns Promise<{ ok: true } | { error?: Error; ok: false; reason: string }>

close

  • close(force): Promise<void>
  • Closes the database connection (aka disconnect)


    Parameters

    • optionalforce: boolean

    Returns Promise<void>

commit

  • commit(ctx, eventBroadcaster, loggerContext): Promise<void>

abstractconnect

  • connect(options): void | Promise<void>
  • Establishes connection to database


    Parameters

    • optionaloptions: { skipOnConnect?: boolean }
      • optionalskipOnConnect: boolean

    Returns void | Promise<void>

ensureConnection

  • ensureConnection(): Promise<void>
  • Ensure the connection exists, this is used to support lazy connect when using new MikroORM() instead of the async init method.


    Returns Promise<void>

abstractexecute

  • execute<T>(query, params, method, ctx): Promise<any>
  • Executes a raw query and returns the result.


    Parameters

    • query: string
    • optionalparams: any[]
    • optionalmethod: get | all | run
    • optionalctx: any

    Returns Promise<any>

executeDump

  • executeDump(dump): Promise<void>
  • Execute raw SQL queries, handy from running schema dump loaded from a file. This method doesn't support transactions, as opposed to orm.schema.execute(), which is used internally.


    Parameters

    • dump: string

    Returns Promise<void>

getConnectionOptions

  • Parses and returns the resolved connection configuration (host, port, user, etc.).


    Returns ConnectionConfig

getNativeClient

  • getNativeClient(): Promise<unknown>
  • Returns the underlying database client the connection drives — e.g. the pg pool, the better-sqlite3 database, or the PGlite instance — for vendor APIs MikroORM does not wrap. Each driver narrows the return type to its own client. Its lifecycle belongs to the ORM, so leave closing it to orm.close() unless you supplied the client yourself via driverOptions.


    Returns Promise<unknown>

getPlatform

  • Returns the platform abstraction for this connection.


    Returns Platform

abstractisConnected

  • isConnected(): Promise<boolean>
  • Are we connected to the database


    Returns Promise<boolean>

rollback

  • rollback(ctx, eventBroadcaster, loggerContext): Promise<void>

setMetadata

  • setMetadata(metadata): void
  • Sets the metadata storage on this connection.


    Parameters

    Returns void

setPlatform

  • setPlatform(platform): void
  • Sets the platform abstraction on this connection.


    Parameters

    Returns void

transactional

  • transactional<T>(cb, options): Promise<T>
  • Executes a callback inside a transaction, committing on success and rolling back on failure.


    Parameters

    Returns Promise<T>