-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnames.go
More file actions
64 lines (53 loc) · 1.38 KB
/
names.go
File metadata and controls
64 lines (53 loc) · 1.38 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package scaf
// Database names.
const (
DatabaseNeo4j = "neo4j"
DatabasePostgres = "postgres"
DatabaseMySQL = "mysql"
DatabaseSQLite = "sqlite"
)
// Dialect names.
const (
DialectCypher = "cypher"
DialectSQL = "sql"
)
// Adapter names (for code generation).
const (
AdapterNeogo = "neogo"
AdapterPgx = "pgx"
AdapterMySQL = "mysql"
AdapterSQLite = "sqlite"
)
// Language names.
const (
LangGo = "go"
)
// DatabaseInfo maps database names to their dialect and default adapter.
type DatabaseInfo struct {
Dialect string
Adapter string // default adapter for Go
}
// KnownDatabases maps database names to their info.
var KnownDatabases = map[string]DatabaseInfo{
DatabaseNeo4j: {Dialect: DialectCypher, Adapter: AdapterNeogo},
DatabasePostgres: {Dialect: DialectSQL, Adapter: AdapterPgx},
DatabaseMySQL: {Dialect: DialectSQL, Adapter: AdapterMySQL},
DatabaseSQLite: {Dialect: DialectSQL, Adapter: AdapterSQLite},
}
// DialectForDatabase returns the dialect name for a database.
func DialectForDatabase(dbName string) string {
if info, ok := KnownDatabases[dbName]; ok {
return info.Dialect
}
return ""
}
// AdapterForDatabase returns the default adapter name for a database and language.
func AdapterForDatabase(dbName, lang string) string {
if lang != LangGo {
return ""
}
if info, ok := KnownDatabases[dbName]; ok {
return info.Adapter
}
return ""
}