You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lib/src/orm/connection/event/QueryExecutedEventSerialize...

38 lines
1.3 KiB

import {BaseSerializer, ObjectSerializer} from '../../../support/bus'
import {QueryExecutedEvent} from './QueryExecutedEvent'
import {Awaitable, JSONState} from '../../../util'
import {Container, Inject, Injectable} from '../../../di'
import {DatabaseService} from '../../DatabaseService'
export interface QueryExecutedEventSerialPayload extends JSONState {
connectionName: string
query: string
}
@ObjectSerializer()
@Injectable()
export class QueryExecutedEventSerializer extends BaseSerializer<QueryExecutedEvent, QueryExecutedEventSerialPayload> {
@Inject()
protected readonly injector!: Container
protected decodeSerial(serial: QueryExecutedEventSerialPayload): Awaitable<QueryExecutedEvent> {
const connection = this.injector.make<DatabaseService>(DatabaseService).get(serial.connectionName)
return new QueryExecutedEvent(serial.connectionName, connection, serial.query)
}
protected encodeActual(actual: QueryExecutedEvent): Awaitable<QueryExecutedEventSerialPayload> {
return {
connectionName: actual.connectionName,
query: actual.query,
}
}
protected getName(): string {
return '@extollo/lib.QueryExecutedEventSerializer'
}
matchActual(some: QueryExecutedEvent): boolean {
return some instanceof QueryExecutedEvent
}
}