File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ function copyToClipboard(text: string) {
2727}
2828
2929function sqlFormat(query : string ) {
30- return format (query , { language: configStore .config .activeRecord . adapter })
30+ return format (query , { language: configStore .config .sqlDialect })
3131}
3232 </script >
3333
Original file line number Diff line number Diff line change 11import defaultsDeep from "lodash/defaultsDeep"
2+ import { SqlLanguage } from "sql-formatter"
23
34export type DebugbarConfigOptions = {
45 mode : "ws" | "poll" | "off"
@@ -17,13 +18,27 @@ export type DebugbarConfigOptions = {
1718 activeRecord : {
1819 adapter : "mysql" | "postgresql" | "sql" | "sqlite"
1920 }
21+ sqlDialect : SqlLanguage
2022}
2123
2224export type DebugbarConfig = DebugbarConfigOptions & {
2325 actionCableUrl : string
2426 pollUrl : string
2527}
2628
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+
2742export function newDebugbarConfig ( options : DebugbarConfigOptions ) {
2843 const obj : DebugbarConfig = defaultsDeep ( options , {
2944 mode : "ws" ,
@@ -47,5 +62,7 @@ export function newDebugbarConfig(options: DebugbarConfigOptions) {
4762 obj . actionCableUrl = `${ obj . cable . url } ${ obj . prefix } /cable`
4863 obj . pollUrl = `${ obj . poll . url } ${ obj . prefix } /poll`
4964
65+ obj . sqlDialect = sqlDialect ( obj . activeRecord . adapter )
66+
5067 return obj
5168}
You can’t perform that action at this time.
0 commit comments