/* * Copyright (c) 2022 EdgerOS Team. * All rights reserved. * * Detailed license information can be found in the LICENSE file. * * Author : 薛强 * Date : 2024-11-14 10:57:28 * LastEditors : 薛强 * LastEditTime : 2024-11-26 14:34:55 */ import { type ClientOptions, DriverMgr } from './driver-mgr' import type IDriver from './i-driver' export { DriverMgr, DB_TYPE, type ClientOptions, type ETCDClientOptions, type SQLiteClientOptions } from './driver-mgr' export class Driver implements IDriver { private readonly options: ClientOptions private client: IDriver private readonly manager: DriverMgr constructor(options: ClientOptions) { this.options = options const driverMgr = new DriverMgr() this.manager = driverMgr } async init(options: ClientOptions): Promise { await this.manager.init(options) this.client = this.manager.driver } async exec(service: any, method: string, params: unknown, options?: any): Promise { return await this.client.exec(service, method, params, options) } async withConnection(service: any, fn: (args: { resource: any, client: any }) => Promise | R): Promise { return await this.client.withConnection(service, fn) } markFailed(resource: any, error: Error): void { this.client.markFailed(resource, error) } callOptionsFactory: any /** * Tears down all ongoing connections and resoruces. */ public close() { this.manager.close() } }