netmaker/db/connector.go
Vishal Dalwadi 7f40371ffd
Task/DB-Migration: Add Key-Value to SQL Migration functionality. (#3380)
* 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;
2025-04-12 14:07:57 +04:00

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
}
}