MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / NewDSN

Function NewDSN

storage/dsn.go:31–54  ·  view source on GitHub ↗

NewDSN parses the given string and returns a DSN.

(s string)

Source from the content-addressed store, hash-verified

29
30// NewDSN parses the given string and returns a DSN.
31func NewDSN(s string) (*DSN, error) {
32 parts := strings.SplitN(s, "?", 2)
33
34 dsn := &DSN{
35 filename: strings.TrimPrefix(parts[0], "file:"),
36 params: make(map[string]string),
37 }
38
39 if len(parts) < 2 {
40 return dsn, nil
41 }
42
43 for _, v := range strings.Split(parts[1], "&") {
44 param := strings.SplitN(v, "=", 2)
45
46 if len(param) != 2 {
47 return nil, fmt.Errorf("unrecognized parameter: %s", v)
48 }
49
50 dsn.params[param[0]] = param[1]
51 }
52
53 return dsn, nil
54}
55
56// Format formats DSN to a connection string.
57func (dsn *DSN) Format() string {

Callers 5

NewSqliteFunction · 0.92
NewDatabaseFunction · 0.92
openDBFunction · 0.85
CloseMethod · 0.85
TestDSNFunction · 0.85

Calls 1

ErrorfMethod · 0.80

Tested by 1

TestDSNFunction · 0.68