-
Notifications
You must be signed in to change notification settings - Fork 26
/
dialect.go
48 lines (37 loc) · 1.1 KB
/
dialect.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package sql
import (
"fmt"
"log/slog"
"strings"
)
type Dialect interface {
QuoteIdentifier(identifier string) string
}
type DefaultDialect struct{}
func (DefaultDialect) QuoteIdentifier(identifier string) string {
return fmt.Sprintf(`"%s"`, identifier)
}
type BigQueryDialect struct{}
func (BigQueryDialect) QuoteIdentifier(identifier string) string {
// BigQuery needs backticks to quote.
return fmt.Sprintf("`%s`", identifier)
}
type RedshiftDialect struct{}
func (rd RedshiftDialect) QuoteIdentifier(identifier string) string {
// Preserve the existing behavior of Redshift identifiers being lowercased due to not being quoted.
return fmt.Sprintf(`"%s"`, strings.ToLower(identifier))
}
type SnowflakeDialect struct {
UppercaseEscNames bool
}
func (sd SnowflakeDialect) QuoteIdentifier(identifier string) string {
if sd.UppercaseEscNames {
identifier = strings.ToUpper(identifier)
} else {
slog.Warn("Escaped Snowflake identifier is not being uppercased",
slog.String("name", identifier),
slog.Bool("uppercaseEscapedNames", sd.UppercaseEscNames),
)
}
return fmt.Sprintf(`"%s"`, identifier)
}