Copyright 2021 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

package postgres

import (
	
	
	

	
	
	
	
	
	
	
	
)
GetSymbolHistory returns a SymbolHistory, which is a representation of the first version when a symbol is added to an API.
func ( *DB) ( context.Context, ,  string,
) ( *internal.SymbolHistory,  error) {
	defer derrors.Wrap(&, "GetSymbolHistory(ctx, %q, %q)", , )
	defer middleware.ElapsedStat(, "GetSymbolHistory")()

	if  == stdlib.ModulePath {
		return GetSymbolHistoryFromTable(, .db, , )
	}
	if experiment.IsActive(, internal.ExperimentReadSymbolHistory) {
		return GetSymbolHistoryFromTable(, .db, , )
	}
	return GetSymbolHistoryWithPackageSymbols(, .db, , )
}
GetSymbolHistoryFromTable returns a SymbolHistory, which is a representation of the first version when a symbol is added to an API. It reads data from the symbol_history table.
func ( context.Context,  *database.DB,
	,  string) ( *internal.SymbolHistory,  error) {
	defer derrors.WrapStack(&, "GetSymbolHistoryFromTable(ctx, ddb, %q, %q)", , )

	 := squirrel.Select(
		"s1.name AS symbol_name",
		"s2.name AS parent_symbol_name",
		"ps.section",
		"ps.type",
		"ps.synopsis",
		"sh.since_version",
		"sh.goos",
		"sh.goarch",
	).From("symbol_history sh").
		Join("package_symbols ps ON ps.id = sh.package_symbol_id").
		Join("symbol_names s1 ON ps.symbol_name_id = s1.id").
		Join("symbol_names s2 ON ps.parent_symbol_name_id = s2.id").
		Join("paths p1 ON sh.package_path_id = p1.id").
		Join("paths p2 ON sh.module_path_id = p2.id").
		Where(squirrel.Eq{"p1.path": }).
		Where(squirrel.Eq{"p2.path": })
	, ,  := .PlaceholderFormat(squirrel.Dollar).ToSql()
	if  != nil {
		return nil, 
	}

	,  := collectSymbolHistory(func(*internal.SymbolHistory, internal.SymbolMeta, string, internal.BuildContext) error { return nil })
	if  := .RunQuery(, , , ...);  != nil {
		return nil, 
	}
	return , nil
}
GetSymbolHistoryWithPackageSymbols fetches symbol history data by using data from package_symbols and documentation_symbols, and computed using symbol.IntroducedHistory. GetSymbolHistoryWithPackageSymbols is exported for use in tests.
func ( context.Context,  *database.DB,
	,  string) ( *internal.SymbolHistory,  error) {
	defer derrors.WrapStack(&, "GetSymbolHistoryWithPackageSymbols(ctx, ddb, %q, %q)", , )
	defer middleware.ElapsedStat(, "GetSymbolHistoryWithPackageSymbols")()
	,  := getPackageSymbols(, , , )
	if  != nil {
		return nil, 
	}
	return symbol.IntroducedHistory()
}
GetSymbolHistoryForBuildContext returns a map of the first version when a symbol name is added to the API for the specified build context, to the symbol name, to the UnitSymbol struct. The UnitSymbol.Children field will always be empty, as children names are also tracked.
func ( context.Context,  *database.DB,  int,  string,
	 internal.BuildContext) ( map[string]string,  error) {
	defer derrors.WrapStack(&, "GetSymbolHistoryForBuildContext(ctx, ddb, %d, %q)", , )
	defer middleware.ElapsedStat(, "GetSymbolHistoryForBuildContext")()

	if  == internal.BuildContextAll {
		 = internal.BuildContextLinux
	}

	 := squirrel.Select(
		"s1.name AS symbol_name",
		"sh.since_version",
	).From("symbol_history sh").
		Join("package_symbols ps ON ps.id = sh.package_symbol_id").
		Join("symbol_names s1 ON ps.symbol_name_id = s1.id").
		Join("symbol_names s2 ON ps.parent_symbol_name_id = s2.id").
		Join("paths p2 ON sh.module_path_id = p2.id").
		Where(squirrel.Eq{"sh.package_path_id": }).
		Where(squirrel.Eq{"p2.path": }).
		Where(squirrel.Eq{"sh.goos": .GOOS}).
		Where(squirrel.Eq{"sh.goarch": .GOARCH})
	, ,  := .PlaceholderFormat(squirrel.Dollar).ToSql()
	if  != nil {
		return nil, 
	}
versionToNameToUnitSymbol is a map of the version a symbol was introduced, to the name and unit symbol.
	 := map[string]string{}
	 := func( *sql.Rows) error {
		var ,  string
		if  := .Scan(&, &);  != nil {
			return fmt.Errorf("row.Scan(): %v", )
		}
		[] = 
		return nil
	}
	if  := .RunQuery(, , , ...);  != nil {
		return nil, 
	}
	return , nil