99 SelectOption ,
1010 UpdateOption , UpdateResult , UpdateRow ,
1111 PoolConnectionPromisify ,
12+ Logging ,
1213} from './types' ;
1314import channels from './channels' ;
1415import type { QueryStartMessage , QueryEndMessage } from './channels' ;
@@ -20,6 +21,8 @@ const debug = debuglog('ali-rds:operator');
2021 */
2122export abstract class Operator {
2223 #connection: PoolConnectionPromisify ;
24+ logging ?: Logging ;
25+
2326 constructor ( connection ?: PoolConnectionPromisify ) {
2427 if ( connection ) {
2528 this . #connection = connection ;
@@ -43,6 +46,10 @@ export abstract class Operator {
4346 this . afterQueryHandlers . push ( afterQueryHandler ) ;
4447 }
4548
49+ setLogging ( logging ?: Logging ) {
50+ this . logging = logging ;
51+ }
52+
4653 escape ( value : any , stringifyObjects ?: boolean , timeZone ?: string ) : string {
4754 return SqlString . escape ( value , stringifyObjects , timeZone ) ;
4855 }
@@ -80,6 +87,9 @@ export abstract class Operator {
8087 }
8188 }
8289 debug ( '[connection#%s] query %o' , this . threadId , sql ) ;
90+ if ( typeof this . logging === 'function' ) {
91+ this . logging ( sql , { threadId : this . threadId } ) ;
92+ }
8393 const queryStart = performance . now ( ) ;
8494 let rows : any ;
8595 let lastError : Error | undefined ;
0 commit comments