Add query executed event; forward model events to global event bus
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2021-06-05 08:36:35 -05:00
parent 61731c4ebd
commit c264d45927
4 changed files with 91 additions and 1 deletions

View File

@@ -2,6 +2,9 @@ import {ErrorWithContext} from '../../util'
import {QueryResult} from '../types'
import {SQLDialect} from '../dialect/SQLDialect'
import {AppClass} from '../../lifecycle/AppClass'
import {Inject, Injectable} from '../../di'
import {EventBus} from '../../event/EventBus'
import {QueryExecutedEvent} from './event/QueryExecutedEvent'
/**
* Error thrown when a connection is used before it is ready.
@@ -18,7 +21,10 @@ export class ConnectionNotReadyError extends ErrorWithContext {
* Abstract base class for database connections.
* @abstract
*/
@Injectable()
export abstract class Connection extends AppClass {
@Inject()
protected bus!: EventBus
constructor(
/**
@@ -64,4 +70,14 @@ export abstract class Connection extends AppClass {
// public abstract tables(database_name: string): Promise<Collection<Table>>
// public abstract table(database_name: string, table_name: string): Promise<Table | undefined>
/**
* Fire a QueryExecutedEvent for the given query string.
* @param query
* @protected
*/
protected async queryExecuted(query: string): Promise<void> {
const event = new QueryExecutedEvent(this.name, this, query)
await this.bus.dispatch(event)
}
}