-
Notifications
You must be signed in to change notification settings - Fork 109
/
Copy pathcanonicalize.go
43 lines (35 loc) · 1.07 KB
/
canonicalize.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
// Copyright © 2023 Ory Corp
// SPDX-License-Identifier: Apache-2.0
package dbal
import "github.com/ory/x/cmdx"
const (
// DriverMySQL is the mysql driver name.
DriverMySQL = "mysql"
// DriverPostgreSQL is the postgres driver name.
DriverPostgreSQL = "postgres"
// DriverCockroachDB is the cockroach driver name.
DriverCockroachDB = "cockroach"
// UnknownDriver is the driver name if the driver is unknown.
UnknownDriver = "unknown"
)
// Canonicalize returns constants DriverMySQL, DriverPostgreSQL, DriverCockroachDB, UnknownDriver, depending on `database`.
func Canonicalize(database string) string {
switch database {
case "mysql":
return DriverMySQL
case "pgx", "pq", "postgres", "postgresql":
return DriverPostgreSQL
case "cockroach":
return DriverCockroachDB
default:
return UnknownDriver
}
}
// MustCanonicalize returns constants DriverMySQL, DriverPostgreSQL, DriverCockroachDB or fatals.
func MustCanonicalize(database string) string {
d := Canonicalize(database)
if d == UnknownDriver {
cmdx.Fatalf("Unknown database driver: %s", database)
}
return d
}