aboutsummaryrefslogtreecommitdiff
path: root/internal/dialect.go
diff options
context:
space:
mode:
authorStefan Majewsky <majewsky@gmx.net>2026-04-10 20:13:15 +0200
committerStefan Majewsky <majewsky@gmx.net>2026-04-10 20:13:15 +0200
commit293e2a52e0b45065db12ff27f89f1adebe4bf4d2 (patch)
tree2e7efecdf5ee359df9c6b09ece3443ea33432462 /internal/dialect.go
parente0fb5aa0acc1983648ab1480f22114aead234eeb (diff)
downloadgo-oblast-293e2a52e0b45065db12ff27f89f1adebe4bf4d2.tar.gz
reorganize code
Diffstat (limited to 'internal/dialect.go')
-rw-r--r--internal/dialect.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/internal/dialect.go b/internal/dialect.go
new file mode 100644
index 0000000..0cf90a2
--- /dev/null
+++ b/internal/dialect.go
@@ -0,0 +1,41 @@
+// SPDX-FileCopyrightText: 2026 Stefan Majewsky <majewsky@gmx.net>
+// SPDX-License-Identifier: Apache-2.0
+
+package internal
+
+import (
+ "strconv"
+ "strings"
+)
+
+// Dialect is a copy of the interface of the same name in package oblast.
+// We cannot refer to that interface within this package because that would constitute a cyclic dependency.
+type Dialect interface {
+ Placeholder(i int) string
+ QuoteIdentifier(name string) string
+ UsesLastInsertID() bool
+ InsertSuffixForAutoColumns(columns []string) string
+}
+
+// PostgresDialect is the dialect of PostgreSQL databases.
+type PostgresDialect struct{}
+
+func (PostgresDialect) Placeholder(i int) string { return "$" + strconv.Itoa(i) }
+func (PostgresDialect) QuoteIdentifier(name string) string { return `"` + name + `"` }
+func (PostgresDialect) UsesLastInsertID() bool { return false }
+
+func (p PostgresDialect) InsertSuffixForAutoColumns(columns []string) string {
+ quotedColumns := make([]string, len(columns))
+ for idx, name := range columns {
+ quotedColumns[idx] = p.QuoteIdentifier(name)
+ }
+ return ` RETURNING ` + strings.Join(quotedColumns, ", ")
+}
+
+// SqliteDialect is the dialect of SQLite databases.
+type SqliteDialect struct{}
+
+func (SqliteDialect) Placeholder(_ int) string { return "?" }
+func (SqliteDialect) QuoteIdentifier(name string) string { return `"` + name + `"` }
+func (SqliteDialect) UsesLastInsertID() bool { return true }
+func (SqliteDialect) InsertSuffixForAutoColumns(columns []string) string { return "" }