MCPcopy
hub / github.com/mudler/LocalAI / buildSQLiteDSN

Function buildSQLiteDSN

core/http/auth/db_sqlite.go:30–53  ·  view source on GitHub ↗

buildSQLiteDSN augments a SQLite file path with connection pragmas that make the auth DB resilient on slow or contended storage. - _busy_timeout=5000 makes SQLite retry for up to 5s on SQLITE_BUSY instead of failing immediately. Network-backed storage (SMB/CIFS/NFS, e.g. Azure Files) is prone to tr

(path string)

Source from the content-addressed store, hash-verified

28//
29// Caller-supplied values for either pragma are preserved.
30func buildSQLiteDSN(path string) string {
31 base := path
32 rawQuery := ""
33 if i := strings.IndexByte(path, '?'); i >= 0 {
34 base = path[:i]
35 rawQuery = path[i+1:]
36 }
37
38 values, err := url.ParseQuery(rawQuery)
39 if err != nil {
40 // An unparseable query string means a hand-crafted DSN we should not
41 // risk corrupting; leave it untouched.
42 return path
43 }
44
45 if values.Get("_busy_timeout") == "" {
46 values.Set("_busy_timeout", "5000")
47 }
48 if values.Get("_txlock") == "" {
49 values.Set("_txlock", "immediate")
50 }
51
52 return base + "?" + values.Encode()
53}

Callers 2

db_sqlite_test.goFile · 0.85
openSQLiteDialectorFunction · 0.85

Calls 3

EncodeMethod · 0.80
GetMethod · 0.65
SetMethod · 0.65

Tested by

no test coverage detected