1
This commit is contained in:
+19
-19
@@ -46,11 +46,11 @@ func Resolve(root, name string) (string, error) {
|
||||
return full, nil
|
||||
}
|
||||
|
||||
// splitOwnerName splits a smart-HTTP/SSH repo path "owner/name.git" into its
|
||||
// IState (owner, name) form: both without the ".git" suffix. owner may itself
|
||||
// contain "/" for nested namespaces (e.g. "org/team/name.git" -> owner
|
||||
// "org/team", name "name"); name is always the final segment. IState
|
||||
// reconstructs the on-disk path / DB full-name as owner+"/"+name+".git".
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
func SplitRepo(repo string) (owner, name string, err error) {
|
||||
s := strings.TrimSuffix(repo, ".git")
|
||||
i := strings.LastIndex(s, "/")
|
||||
@@ -60,12 +60,12 @@ func SplitRepo(repo string) (owner, name string, err error) {
|
||||
return s[:i], s[i+1:], nil
|
||||
}
|
||||
|
||||
// parseDBURI maps a URI scheme to (driver, dsn), following simpleconsole's
|
||||
// ParseDBURI convention so the same URIs work across both services. Unexported:
|
||||
// Open is the only entry point callers need.
|
||||
//
|
||||
// sqlite://<path>[?_pragma=...] -> driver "sqlite3", modernc DSN "file:<path>?..."
|
||||
// postgres://<dsn-url> -> driver "postgres", dsn passed through verbatim
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
func ParseDBURI(root, uri string) (driver, dsn string, uriNew string, err error) {
|
||||
if uri == "" {
|
||||
return "", "", "", fmt.Errorf("database URI is empty")
|
||||
@@ -83,17 +83,17 @@ func ParseDBURI(root, uri string) (driver, dsn string, uriNew string, err error)
|
||||
uriNew := "sqlite3://" + filepath.Join(root, path)
|
||||
return "sqlite3", sqliteDSN(filepath.Join(root, path), query), uriNew, nil
|
||||
case "postgres", "postgresql":
|
||||
// lib/pq parses the URL form natively; pass it through unchanged.
|
||||
|
||||
return "postgres", uri, uri, nil
|
||||
default:
|
||||
return "", "", "", fmt.Errorf("unsupported database URI scheme %q (want sqlite:// or postgres://)", scheme)
|
||||
}
|
||||
}
|
||||
|
||||
// sqliteDSN builds a modernc DSN: "file:<path>?<params>". Default pragmas (WAL,
|
||||
// busy_timeout, foreign_keys) and _txlock=immediate are applied only when the
|
||||
// caller supplied no pragmas of their own; an explicit pragma set is respected
|
||||
// verbatim.
|
||||
|
||||
|
||||
|
||||
|
||||
func sqliteDSN(path, query string) string {
|
||||
v, _ := url.ParseQuery(query)
|
||||
if len(v["_pragma"]) == 0 {
|
||||
@@ -105,7 +105,7 @@ func sqliteDSN(path, query string) string {
|
||||
return "file:" + path + "?" + v.Encode()
|
||||
}
|
||||
|
||||
// sqlitePath extracts the file path from a modernc DSN ("file:<path>?...").
|
||||
|
||||
func sqlitePath(dsn string) string {
|
||||
s := strings.TrimPrefix(dsn, "file:")
|
||||
if i := strings.Index(s, "?"); i >= 0 {
|
||||
@@ -114,8 +114,8 @@ func sqlitePath(dsn string) string {
|
||||
return s
|
||||
}
|
||||
|
||||
// splitScheme splits "scheme:rest" at the first colon. ok is false when there
|
||||
// is no colon.
|
||||
|
||||
|
||||
func splitScheme(uri string) (scheme, rest string, ok bool) {
|
||||
i := strings.Index(uri, ":")
|
||||
if i < 0 {
|
||||
|
||||
Reference in New Issue
Block a user