File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ function copyToClipboard(text: string) {
27
27
}
28
28
29
29
function sqlFormat(query : string ) {
30
- return format (query , { language: configStore .config .activeRecord . adapter })
30
+ return format (query , { language: configStore .config .sqlDialect })
31
31
}
32
32
</script >
33
33
Original file line number Diff line number Diff line change 1
1
import defaultsDeep from "lodash/defaultsDeep"
2
+ import { SqlLanguage } from "sql-formatter"
2
3
3
4
export type DebugbarConfigOptions = {
4
5
mode : "ws" | "poll" | "off"
@@ -17,13 +18,27 @@ export type DebugbarConfigOptions = {
17
18
activeRecord : {
18
19
adapter : "mysql" | "postgresql" | "sql" | "sqlite"
19
20
}
21
+ sqlDialect : SqlLanguage
20
22
}
21
23
22
24
export type DebugbarConfig = DebugbarConfigOptions & {
23
25
actionCableUrl : string
24
26
pollUrl : string
25
27
}
26
28
29
+ function sqlDialect ( arAdapter ) : SqlLanguage {
30
+ // We use regex to handle adapter names like "mysql2", "jdbcpostgresql", etc.
31
+ if ( / m y s q l | t r i o l o g y / . test ( arAdapter ) ) {
32
+ return "mysql"
33
+ } else if ( / p g | p o s t g r e s / . test ( arAdapter ) ) {
34
+ return "postgresql"
35
+ } else if ( / s q l i t e / . test ( arAdapter ) ) {
36
+ return "sqlite"
37
+ } else {
38
+ return "sql"
39
+ }
40
+ }
41
+
27
42
export function newDebugbarConfig ( options : DebugbarConfigOptions ) {
28
43
const obj : DebugbarConfig = defaultsDeep ( options , {
29
44
mode : "ws" ,
@@ -47,5 +62,7 @@ export function newDebugbarConfig(options: DebugbarConfigOptions) {
47
62
obj . actionCableUrl = `${ obj . cable . url } ${ obj . prefix } /cable`
48
63
obj . pollUrl = `${ obj . poll . url } ${ obj . prefix } /poll`
49
64
65
+ obj . sqlDialect = sqlDialect ( obj . activeRecord . adapter )
66
+
50
67
return obj
51
68
}
You can’t perform that action at this time.
0 commit comments