mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-06 21:24:16 +08:00
* feat(go): add db package; * feat(go): add jobs table; * feat(go): add schema migration facade; * refactor(go): use custom key type to avoid collisions;
28 lines
603 B
Go
28 lines
603 B
Go
package db
|
|
|
|
import (
|
|
"errors"
|
|
"github.com/gravitl/netmaker/servercfg"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
var ErrUnsupportedDB = errors.New("unsupported db type")
|
|
|
|
// connector helps connect to a database,
|
|
// along with any initializations required.
|
|
type connector interface {
|
|
connect() (*gorm.DB, error)
|
|
}
|
|
|
|
// newConnector detects the database being
|
|
// used and returns the corresponding connector.
|
|
func newConnector() (connector, error) {
|
|
switch servercfg.GetDB() {
|
|
case "sqlite":
|
|
return &sqliteConnector{}, nil
|
|
case "postgres":
|
|
return &postgresConnector{}, nil
|
|
default:
|
|
return nil, ErrUnsupportedDB
|
|
}
|
|
}
|