1
+ import { format } from "@sqltools/formatter" ;
1
2
import type { Logger } from "drizzle-orm/logger" ;
2
3
import { colors } from "./colors" ;
3
4
@@ -104,16 +105,16 @@ export class EnhancedQueryLogger implements Logger {
104
105
return `${ colors . dim } $${ index + 1 } :${ colors . reset } ${ value } ` ;
105
106
} ) ;
106
107
107
- return `\n ${ colors . gray } ├─ Parameters: ${
108
- colors . reset
109
- } ${ formattedParams . join ( ", " ) } `;
108
+ return `${ colors . gray } ├─ Parameters: ${ colors . reset } ${
109
+ formattedParams . join ( ", " )
110
+ } `;
110
111
}
111
112
112
113
private formatQuery ( query : string ) : string {
113
114
return query
114
115
. replace (
115
116
/ \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 } ` ,
117
118
)
118
119
. replace ( / ( ' [ ^ ' ] * ' | " [ ^ " ] * " ) / g, `${ colors . green } $1${ colors . reset } ` )
119
120
. replace ( / \b ( \d + ) \b / g, `${ colors . cyan } $1${ colors . reset } ` ) ;
@@ -136,7 +137,10 @@ export class EnhancedQueryLogger implements Logger {
136
137
const typeColor = this . getQueryTypeColor ( queryType ) ;
137
138
const icon = this . getQueryTypeIcon ( queryType ) ;
138
139
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
+ ) ;
140
144
141
145
const header = `${ colors . bright } ${ colors . cyan } ╭─ Database Query ${ colors . dim } #${ this . queryCount } ${ colors . reset } ` ;
142
146
const timeInfo = `${ colors . gray } │ ${ colors . dim } Time: ${ timestamp } ${ colors . reset } ` ;
@@ -149,15 +153,15 @@ export class EnhancedQueryLogger implements Logger {
149
153
} `;
150
154
const queryLine = `${ colors . gray } │ ${ colors . dim } SQL:${ colors . reset } ${ formattedQuery } ` ;
151
155
const footer = `${ colors . gray } ╰─${ colors . dim } ${ "─" . repeat ( 50 ) } ${
152
- colors . reset
153
- } `;
156
+ colors . reset }
157
+ ` ;
154
158
155
159
this . options . log ( "\n" + header ) ;
156
160
this . options . log ( timeInfo ) ;
157
161
this . options . log ( queryInfo ) ;
158
162
this . options . log ( queryLine ) ;
159
163
if ( paramsStr ) {
160
- this . options . log ( ` ${ colors . gray } ${ paramsStr } ` ) ;
164
+ this . options . log ( paramsStr ) ;
161
165
}
162
166
this . options . log ( footer ) ;
163
167
0 commit comments