@@ -67,10 +67,30 @@ export class LockedAsyncDatabaseAdapter
6767 const start = performance . now ( ) ;
6868 try {
6969 const r = await originalExecute ( sql , bindings ) ;
70+ const duration = performance . now ( ) - start ;
7071 performance . measure ( `[SQL] ${ sql } ` , { start } ) ;
72+ console . log (
73+ '%c[SQL] %c%s %c%s' ,
74+ 'color: grey; font-weight: normal' ,
75+ durationStyle ( duration ) ,
76+ `[${ duration . toFixed ( 1 ) } ms]` ,
77+ 'color: grey; font-weight: normal' ,
78+ sql
79+ ) ;
7180 return r ;
7281 } catch ( e : any ) {
82+ const duration = performance . now ( ) - start ;
7383 performance . measure ( `[SQL] [ERROR: ${ e . message } ] ${ sql } ` , { start } ) ;
84+ console . error (
85+ '%c[SQL] %c%s %c%s %c%s' ,
86+ 'color: grey; font-weight: normal' ,
87+ 'color: red; font-weight: normal' ,
88+ `[ERROR: ${ e . message } ]` ,
89+ durationStyle ( duration ) ,
90+ `[${ duration . toFixed ( 1 ) } ms]` ,
91+ 'color: grey; font-weight: normal' ,
92+ sql
93+ ) ;
7494 throw e ;
7595 }
7696 } ;
@@ -356,3 +376,13 @@ export class LockedAsyncDatabaseAdapter
356376 } ;
357377 } ;
358378}
379+
380+ function durationStyle ( duration : number ) {
381+ if ( duration < 30 ) {
382+ return 'color: grey; font-weight: normal' ;
383+ } else if ( duration < 300 ) {
384+ return 'color: blue; font-weight: normal' ;
385+ } else {
386+ return 'color: red; font-weight: normal' ;
387+ }
388+ }
0 commit comments