dal/pkg/adapter/registry.go
Anton Nesterov 7f5c2a32cc
[ref] refactor adapter, add dialect registry for future extensibility
Signed-off-by: Anton Nesterov <anton@demiurg.io>
2024-08-15 09:06:29 +02:00

25 lines
563 B
Go

package adapter
import "fmt"
var DIALECTS = map[string]Dialect{
"sqlite3": CommonDialect{},
}
/**
* Register a new dialect for a given driver name.
* `driverName` is the valid name of the db driver (e.g. "sqlite3", "postgres").
* `dialect` is an implementation of the Dialect interface.
**/
func RegisterDialect(driverName string, dialect Dialect) {
DIALECTS[driverName] = dialect
}
func GetDialect(driverName string) Dialect {
dialect, ok := DIALECTS[driverName]
if !ok {
panic(fmt.Errorf("db driver %s not found", driverName))
}
return dialect
}