package registry import ( "database/sql" "net/url" "path/filepath" "modernc.org/sqlite" ) func OpenReadOnly(path string) (*Registry, error) { absolute, err := filepath.Abs(path) if err != nil { return nil, err } uri := url.URL{Scheme: "file", Path: absolute} query := url.Values{"mode": {"ro"}, "_pragma": {"busy_timeout(5000)", "query_only(1)"}} uri.RawQuery = query.Encode() d := sql.OpenDB(registryConnector{d: &sqlite.Driver{}, path: uri.String()}) d.SetMaxOpenConns(1) if err := d.Ping(); err != nil { d.Close() return nil, err } return &Registry{sql: d, path: path}, nil }