Source File
symbol.go
Belonging Package
golang.org/x/pkgsite/internal/postgres
package postgres
import (
)
func ( context.Context, *database.DB, , string,
map[string]int,
map[string]map[int]*internal.Documentation) ( error) {
defer derrors.WrapStack(&, "insertSymbols(ctx, db, %q, %q, pathToID, pathToDocs)", , )
, := upsertSymbolNamesReturningIDs(, , )
if != nil {
return
}
, := upsertPackageSymbolsReturningIDs(, , , , , )
if != nil {
return
}
if := upsertDocumentationSymbols(, , , ); != nil {
return
}
return upsertSymbolHistory(, , , , ,
, , )
}
type packageSymbol struct {
name string
synopsis string
:= map[int]map[int]bool{}
for , := range {
for , := range {
:= updateSymbols(.API, func( *internal.SymbolMeta) error {
, := []
if ! {
return fmt.Errorf("path could not be found: %q", )
}
:= packageSymbol{synopsis: .Synopsis, name: .Name, parentName: .ParentName}
, := []
if ! {
return fmt.Errorf("package symbol could not be found: %v", )
}
_, = []
if ! {
[] = map[int]bool{}
}
[][] = true
return nil
})
if != nil {
return
}
}
}
:= []string{"documentation_id", "package_symbol_id"}
if := .BulkInsert(, "documentation_symbols", ,
, `
ON CONFLICT (documentation_id, package_symbol_id)
DO UPDATE SET
documentation_id=excluded.documentation_id,
package_symbol_id=excluded.package_symbol_id`); != nil {
return
}
return nil
}
func ( context.Context, *database.DB,
string,
map[string]int,
map[string]int,
map[string]map[int]*internal.Documentation) ( map[string]map[packageSymbol]int, error) {
defer derrors.WrapStack(&, "upsertPackageSymbolsReturningIDs(ctx, db, %q, pathToID, pathToDocIDToDoc)", )
:= map[int]string{}
for , := range {
[] =
}
var []string
:= map[int]string{}
for , := range {
[] =
= append(, )
}
:= []
if == 0 {
return nil, fmt.Errorf("modulePathID cannot be 0: %q", )
}
:= map[string]map[packageSymbol]int{}
:= func( *sql.Rows) error {
var (
, , , int
string
)
if := .Scan(&, &, &, &, &); != nil {
return fmt.Errorf("row.Scan(): %v", )
}
:= []
if , := []; ! {
[] = map[packageSymbol]int{}
}
:= []
if == "" {
return fmt.Errorf("symbol name cannot be empty: %d", )
}
, := []
return nil
}
[][packageSymbol{
synopsis: ,
name: ,
parentName: ,
}] =
return nil
sort.Slice(.API, func(, int) bool {
return .API[].Name < .API[].Name
})
if := updateSymbols(.API, func( *internal.SymbolMeta) error {
:= packageSymbol{synopsis: .Synopsis, name: .Name, parentName: .ParentName}
:= [.Name]
if == 0 {
return fmt.Errorf("symID cannot be 0: %q", .Name)
}
if .ParentName == "" {
.ParentName = .Name
}
:= [.ParentName]
if == 0 {
return fmt.Errorf("parentSymID cannot be 0: %q", .ParentName)
}
if , := [][]; ! {
= append(, ,
, , , .Section, .Kind,
.Synopsis)
}
return nil
}); != nil {
return nil,
}
}
:= []string{"id", "package_path_id", "symbol_name_id", "parent_symbol_name_id", "synopsis"}
if := .BulkInsertReturning(, "package_symbols",
[]string{
"package_path_id",
"module_path_id",
"symbol_name_id",
"parent_symbol_name_id",
"section",
"type",
"synopsis",
}, , database.OnConflictDoNothing, , ); != nil {
return nil,
}
return , nil
}
func ( context.Context, *database.DB,
map[string]map[int]*internal.Documentation) ( map[string]int, error) {
defer derrors.WrapStack(&, "upsertSymbolNamesReturningIDs")
var []string
for , := range {
for , := range {
if := updateSymbols(.API, func( *internal.SymbolMeta) error {
= append(, .Name)
return nil
}); != nil {
return nil,
}
}
}
:= `
SELECT id, name
FROM symbol_names
WHERE name = ANY($1);`
:= map[string]int{}
:= func( *sql.Rows) error {
var (
int
string
)
if := .Scan(&, &); != nil {
return fmt.Errorf("row.Scan(): %v", )
}
[] =
if == 0 {
return fmt.Errorf("id can't be 0: %q", )
}
return nil
}
if := .RunQuery(, , , pq.Array()); != nil {
return nil,
}
sort.Strings()
var []interface{}
for , := range {
if , := []; ! {
= append(, )
}
}
if := .BulkInsertReturning(, "symbol_names", []string{"name"},
, database.OnConflictDoNothing, []string{"id", "name"}, ); != nil {
return nil,
}
return , nil
}
:= `
SELECT
s1.name AS symbol_name,
s2.name AS parent_symbol_name,
ps.section,
ps.type,
ps.synopsis,
d.goos,
d.goarch
FROM documentation_symbols ds
INNER JOIN documentation d ON d.id = ds.documentation_id
INNER JOIN package_symbols ps ON ds.package_symbol_id = ps.id
INNER JOIN symbol_names s1 ON ps.symbol_name_id = s1.id
INNER JOIN symbol_names s2 ON ps.parent_symbol_name_id = s2.id
WHERE d.unit_id = $1
:= map[internal.BuildContext]map[string]*internal.Symbol{}
:= func( *sql.Rows) error {
var (
internal.SymbolMeta
internal.BuildContext
)
if := .Scan(
&.Name, &.ParentName,
&.Section, &.Kind, &.Synopsis,
&.GOOS, &.GOARCH); != nil {
return fmt.Errorf("row.Scan(): %v", )
}
:= &internal.Symbol{
SymbolMeta: ,
GOOS: .GOOS,
GOARCH: .GOARCH,
}
case internal.SymbolSectionTypes:
if .Kind == internal.SymbolKindType {
, := []
if ! {
[] = map[string]*internal.Symbol{}
}
[][.Name] =
[] = append([], )
} else {
, := []
if ! {
return fmt.Errorf("build context %v for parent type %q could not be found for symbol %q", , .ParentName, .Name)
}
, := [.ParentName]
if ! {
return fmt.Errorf("parent type %q could not be found for symbol %q", .ParentName, .Name)
}
.Children = append(.Children, &)
}
default:
[] = append([], )
}
return nil
}
if := .RunQuery(, , , ); != nil {
return nil,
}
return , nil
}
func ( []*internal.Symbol, func( *internal.SymbolMeta) error) error {
for , := range {
if := (&.SymbolMeta); != nil {
return
}
for , := range .Children {
if := (); != nil {
return
}
}
}
return nil
![]() |
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. |