carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package registry
2
3import (
4 "database/sql"
5 "net/url"
6 "path/filepath"
7
8 "modernc.org/sqlite"
9)
10
11func OpenReadOnly(path string) (*Registry, error) {
12 absolute, err := filepath.Abs(path)
13 if err != nil {
14 return nil, err
15 }
16 uri := url.URL{Scheme: "file", Path: absolute}
17 query := url.Values{"mode": {"ro"}, "_pragma": {"busy_timeout(5000)", "query_only(1)"}}
18 uri.RawQuery = query.Encode()
19 d := sql.OpenDB(registryConnector{d: &sqlite.Driver{}, path: uri.String()})
20 d.SetMaxOpenConns(1)
21 if err := d.Ping(); err != nil {
22 d.Close()
23 return nil, err
24 }
25 return &Registry{sql: d, path: path}, nil
26}
27