import { Client , ClientConfig } from "../deps.ts" ; import { BaseModel } from "./model.ts" ; import { sync } from "./sync.ts" ; import { Transaction } from "./transaction.ts" ; ignore let _client ; ignore let _models = [ ] ; /**
 * Global dso instance
 */ export const dso = { /**
     * set true will show exucte/query sql
     */ showQueryLog : false , param force async sync ( force = false ) { for ( const model of _models ) { await sync ( _client , model , force ) ; } } , /**
     * Database client
     */ get client ( ) : Client { return _client ; } , /**
     * all models
     */ get models ( ) { return _models ; } , param model define < T extends BaseModel > ( ModelClass ) { const model = new ModelClass ( ) ; _models . push ( model ) ; return model ; } , transaction : Transaction . transaction , param config async connect ( config ) { if ( config instanceof Client ) { _client = config ; } else { _client = new Client ( ) ; await _client . connect ( config ) ; } return _client ; } , close ( ) { _client . close ( ) ; } } ;