1+ import { format } from "@sqltools/formatter" ;
12import type { Logger } from "drizzle-orm/logger" ;
23import { colors } from "./colors" ;
34
@@ -104,16 +105,16 @@ export class EnhancedQueryLogger implements Logger {
104105 return `${ colors . dim } $${ index + 1 } :${ colors . reset } ${ value } ` ;
105106 } ) ;
106107
107- return `\n ${ colors . gray } ├─ Parameters: ${
108- colors . reset
109- } ${ formattedParams . join ( ", " ) } `;
108+ return `${ colors . gray } ├─ Parameters: ${ colors . reset } ${
109+ formattedParams . join ( ", " )
110+ } `;
110111 }
111112
112113 private formatQuery ( query : string ) : string {
113114 return query
114115 . replace (
115116 / \b ( S E L E C T | F R O M | W H E R E | J O I N | I N S E R T | I N T O | U P D A T E | S E T | D E L E T E | C R E A T E | D R O P | A L T E R | T A B L E | I N D E X | P R I M A R Y | K E Y | F O R E I G N | R E F E R E N C E S | N O T | N U L L | D E F A U L T | U N I Q U E | A U T O _ I N C R E M E N T | I F | E X I S T S | O N | D U P L I C A T E | K E Y | U P D A T E | V A L U E S | O R D E R | B Y | G R O U P | H A V I N G | L I M I T | O F F S E T | I N N E R | L E F T | R I G H T | O U T E R | U N I O N | C A S E | W H E N | T H E N | E L S E | E N D | A S | D I S T I N C T | C O U N T | S U M | A V G | M A X | M I N | A N D | O R | I N | L I K E | B E T W E E N | I S ) \b / gi,
116- match => `${ colors . blue } ${ match . toUpperCase ( ) } ${ colors . reset } `
117+ ( match ) => `${ colors . blue } ${ match . toUpperCase ( ) } ${ colors . reset } ` ,
117118 )
118119 . replace ( / ( ' [ ^ ' ] * ' | " [ ^ " ] * " ) / g, `${ colors . green } $1${ colors . reset } ` )
119120 . replace ( / \b ( \d + ) \b / g, `${ colors . cyan } $1${ colors . reset } ` ) ;
@@ -136,7 +137,10 @@ export class EnhancedQueryLogger implements Logger {
136137 const typeColor = this . getQueryTypeColor ( queryType ) ;
137138 const icon = this . getQueryTypeIcon ( queryType ) ;
138139 const paramsStr = this . formatParams ( params ) ;
139- const formattedQuery = this . formatQuery ( query ) ;
140+ const formattedQuery = this . formatQuery (
141+ `\n${ format ( query ) } `
142+ . replaceAll ( "\n" , `\n${ colors . gray } │\t` ) ,
143+ ) ;
140144
141145 const header = `${ colors . bright } ${ colors . cyan } ╭─ Database Query ${ colors . dim } #${ this . queryCount } ${ colors . reset } ` ;
142146 const timeInfo = `${ colors . gray } │ ${ colors . dim } Time: ${ timestamp } ${ colors . reset } ` ;
@@ -149,15 +153,15 @@ export class EnhancedQueryLogger implements Logger {
149153 } `;
150154 const queryLine = `${ colors . gray } │ ${ colors . dim } SQL:${ colors . reset } ${ formattedQuery } ` ;
151155 const footer = `${ colors . gray } ╰─${ colors . dim } ${ "─" . repeat ( 50 ) } ${
152- colors . reset
153- } `;
156+ colors . reset }
157+ ` ;
154158
155159 this . options . log ( "\n" + header ) ;
156160 this . options . log ( timeInfo ) ;
157161 this . options . log ( queryInfo ) ;
158162 this . options . log ( queryLine ) ;
159163 if ( paramsStr ) {
160- this . options . log ( ` ${ colors . gray } ${ paramsStr } ` ) ;
164+ this . options . log ( paramsStr ) ;
161165 }
162166 this . options . log ( footer ) ;
163167
0 commit comments