Implement tx enabled db vise

This commit is contained in:
lash
2025-01-19 09:04:37 +00:00
parent c0534ede1b
commit 975720919c
8 changed files with 88 additions and 32 deletions

View File

@@ -4,6 +4,7 @@ import (
"fmt"
"net/url"
"path"
"path/filepath"
)
const (
@@ -68,9 +69,19 @@ func probeGdbm(s string) (string, string, bool) {
}
func probeFs(s string) (string, string, bool) {
if !path.IsAbs(s) {
var err error
v, _ := url.Parse(s)
if v.Scheme != "" && v.Scheme != "file://" {
return "", "", false
}
if !path.IsAbs(s) {
s, err = filepath.Abs(s)
if err != nil {
panic(err)
}
}
s = path.Clean(s)
return s, "", true
}
@@ -85,11 +96,13 @@ func probeMem(s string) (string, string, bool) {
func ToConnData(connStr string) (ConnData, error) {
var o ConnData
if connStr == "" {
v, domain, ok := probeMem(connStr)
if ok {
o.typ = DBTYPE_MEM
return o, nil
}
v, domain, ok := probePostgres(connStr)
v, domain, ok = probePostgres(connStr)
if ok {
o.typ = DBTYPE_POSTGRES
o.str = v
@@ -111,11 +124,5 @@ func ToConnData(connStr string) (ConnData, error) {
return o, nil
}
v, _, ok = probeMem(connStr)
if ok {
o.typ = DBTYPE_MEM
return o, nil
}
return o, fmt.Errorf("invalid connection string: %s", connStr)
}