Enable conndata fs, mem

This commit is contained in:
lash 2025-01-14 18:57:04 +00:00
parent 5228aef088
commit adbfab3964
Signed by untrusted user who does not match committer: lash
GPG Key ID: 21D2E7BB88C2A746

View File

@ -9,6 +9,7 @@ import (
const (
DBTYPE_NONE = iota
DBTYPE_MEM
DBTYPE_FS
DBTYPE_GDBM
DBTYPE_POSTGRES
)
@ -54,6 +55,18 @@ func probePostgres(s string) (string, string, bool) {
}
func probeGdbm(s string) (string, string, bool) {
domain := "public"
v, err := url.Parse(s)
if err != nil {
return "", "", false
}
if v.Scheme != "gdbm" {
return "", "", false
}
return s, domain, true
}
func probeFs(s string) (string, string, bool) {
if !path.IsAbs(s) {
return "", "", false
}
@ -61,6 +74,13 @@ func probeGdbm(s string) (string, string, bool) {
return s, "", true
}
func probeMem(s string) (string, string, bool) {
if s != "" {
return "", "", false
}
return "", "", true
}
func ToConnData(connStr string) (ConnData, error) {
var o ConnData
@ -83,5 +103,18 @@ func ToConnData(connStr string) (ConnData, error) {
return o, nil
}
v, _, ok = probeFs(connStr)
if ok {
o.typ = DBTYPE_FS
o.str = v
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)
}