Source File
path.go
Belonging Package
golang.org/x/pkgsite/internal/postgres
package postgres
import (
)
func ( *DB) ( context.Context, string) ( string, int, error) {
defer derrors.WrapStack(&, "DB.GetLatestPathForV1Path(ctx, %q)", )
:= `
SELECT p.path, m.series_path
FROM paths p
INNER JOIN units u ON u.path_id = p.id
INNER JOIN modules m ON u.module_id = m.id
WHERE u.v1path_id = (
SELECT p.id
FROM paths p
INNER JOIN units u ON u.v1path_id = p.id
WHERE p.path = $1
ORDER BY p.path DESC
LIMIT 1
);`
:= map[string]string{} // from unit path to series path
= .db.RunQuery(, , func( *sql.Rows) error {
var , string
if := .Scan(&, &); != nil {
return
}
[] =
return nil
}, )
if != nil {
return "", 0,
}
var (
int
string
)
:= internal.Suffix(, )
:= strings.TrimSuffix(, "/"+)
, := internal.SeriesPathAndMajorVersion()
if == 0 {
return "", 0, fmt.Errorf("bad module path %q", )
}
if <= {
=
=
}
}
= 1
}
return , , nil
}
defer derrors.WrapStack(&, "upsertPath(%q)", )
if , := .Exec(, `LOCK TABLE paths IN EXCLUSIVE MODE`); != nil {
return 0,
}
= .QueryRow(,
`INSERT INTO paths (path) VALUES ($1) ON CONFLICT DO NOTHING RETURNING id`,
).Scan(&)
if == sql.ErrNoRows {
= .QueryRow(,
`SELECT id FROM paths WHERE path = $1`,
).Scan(&)
if == sql.ErrNoRows {
return 0, errors.New("got no rows; shouldn't happen")
}
}
if != nil {
return 0,
}
if == 0 {
return 0, errors.New("zero ID")
}
return , nil
}
func ( context.Context, *database.DB, []string) ( map[string]int, error) {
defer derrors.WrapStack(&, "upsertPaths(%d paths)", len())
= map[string]int{}
:= func( *sql.Rows) error {
var (
int
string
)
if := .Scan(&, &); != nil {
return
}
[] =
return nil
}
if := .RunQuery(, `SELECT id, path FROM paths WHERE path = ANY($1)`,
, pq.Array()); != nil {
return nil,
}
var []interface{}
for , := range {
if , := []; ! {
= append(, )
}
}
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |