2019-12-02 21:05:21 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package dbutil
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// Implementation type of valid DBs.
|
2019-12-02 21:05:21 +00:00
|
|
|
type Implementation int
|
|
|
|
|
|
|
|
const (
|
2020-08-11 15:50:01 +01:00
|
|
|
// Unknown is an unknown db type.
|
2019-12-02 21:05:21 +00:00
|
|
|
Unknown Implementation = iota
|
2020-08-11 15:50:01 +01:00
|
|
|
// Postgres is a Postgresdb type.
|
2019-12-02 21:05:21 +00:00
|
|
|
Postgres
|
2020-08-11 15:50:01 +01:00
|
|
|
// Cockroach is a Cockroachdb type.
|
2019-12-02 21:05:21 +00:00
|
|
|
Cockroach
|
2020-08-11 15:50:01 +01:00
|
|
|
// Bolt is a Bolt kv store.
|
2019-12-02 21:05:21 +00:00
|
|
|
Bolt
|
2020-08-11 15:50:01 +01:00
|
|
|
// Redis is a Redis kv store.
|
2019-12-02 21:05:21 +00:00
|
|
|
Redis
|
2020-08-11 15:50:01 +01:00
|
|
|
// SQLite3 is a sqlite3 database.
|
2020-01-03 19:13:57 +00:00
|
|
|
SQLite3
|
2019-12-02 21:05:21 +00:00
|
|
|
)
|
|
|
|
|
2019-12-05 20:42:12 +00:00
|
|
|
// ImplementationForScheme returns the Implementation that is used for
|
|
|
|
// the url with the provided scheme.
|
|
|
|
func ImplementationForScheme(scheme string) Implementation {
|
|
|
|
switch scheme {
|
2020-06-28 04:56:29 +01:00
|
|
|
case "pgx", "postgres", "postgresql":
|
2019-12-02 21:05:21 +00:00
|
|
|
return Postgres
|
|
|
|
case "cockroach":
|
|
|
|
return Cockroach
|
|
|
|
case "bolt":
|
|
|
|
return Bolt
|
|
|
|
case "redis":
|
|
|
|
return Redis
|
2020-01-03 19:13:57 +00:00
|
|
|
case "sqlite", "sqlite3":
|
|
|
|
return SQLite3
|
2019-12-02 21:05:21 +00:00
|
|
|
default:
|
|
|
|
return Unknown
|
|
|
|
}
|
|
|
|
}
|
2020-01-03 19:13:57 +00:00
|
|
|
|
|
|
|
// SchemeForImplementation returns the scheme that is used for URLs
|
|
|
|
// that use the given Implementation.
|
|
|
|
func SchemeForImplementation(implementation Implementation) string {
|
|
|
|
switch implementation {
|
|
|
|
case Postgres:
|
|
|
|
return "postgres"
|
|
|
|
case Cockroach:
|
|
|
|
return "cockroach"
|
|
|
|
case Bolt:
|
|
|
|
return "bolt"
|
|
|
|
case Redis:
|
|
|
|
return "redis"
|
|
|
|
case SQLite3:
|
|
|
|
return "sqlite3"
|
|
|
|
default:
|
|
|
|
return "<unknown>"
|
|
|
|
}
|
|
|
|
}
|