Skip to content

Commit c40e240

Browse files
better sql dialect detection
1 parent ebf8edc commit c40e240

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

client/src/components/queries/QueryItem.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function copyToClipboard(text: string) {
2727
}
2828
2929
function sqlFormat(query: string) {
30-
return format(query, { language: configStore.config.activeRecord.adapter })
30+
return format(query, { language: configStore.config.sqlDialect })
3131
}
3232
</script>
3333

client/src/models/Config.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import defaultsDeep from "lodash/defaultsDeep"
2+
import { SqlLanguage } from "sql-formatter"
23

34
export 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

2224
export 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 (/mysql|triology/.test(arAdapter)) {
32+
return "mysql"
33+
} else if (/pg|postgres/.test(arAdapter)) {
34+
return "postgresql"
35+
} else if (/sqlite/.test(arAdapter)) {
36+
return "sqlite"
37+
} else {
38+
return "sql"
39+
}
40+
}
41+
2742
export 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
}

0 commit comments

Comments
 (0)