Documentation
¶
Overview ¶
Package psql provides utility functions for working with Postgre in the context of a knowledge database.
Index ¶
- func BatchInsertFriendsOfPhpPackageVulnerabilities(db *bun.DB, items []knowledge.PackageVulnerability) error
- func BatchInsertNvdPackageVulnerabilities(db *bun.DB, items []knowledge.PackageVulnerability) error
- func BatchInsertOsvPackageVulnerabilities(db *bun.DB, items []knowledge.PackageVulnerability) error
- func BatchUpdateFriendsOfPHP(db *bun.DB, advisories []knowledge.FriendsOfPHPAdvisory) error
- func BatchUpdateOsv(db *bun.DB, osvItems []knowledge.OSVItem) error
- func GetAllFriendsOfPHP(db *bun.DB, limit, offset int) ([]knowledge.FriendsOfPHPAdvisory, error)
- func GetFriendsOfPHPByAdvisoryID(db *bun.DB, advisoryId string) (*knowledge.FriendsOfPHPAdvisory, error)
- func GetFriendsOfPHPByPackage(db *bun.DB, packageName string) ([]knowledge.FriendsOfPHPAdvisory, error)
- func GetFriendsOfPhpUUIDsByAdvisoryIds(db *bun.DB, advisoryIds []string) (map[string]uuid.UUID, error)
- func GetNvdUUIDsByNvdIds(db *bun.DB, nvdIds []string) (map[string]uuid.UUID, error)
- func GetOsvByID(db *bun.DB, osvId string) (*knowledge.OSVItem, error)
- func GetOsvIdsForPackage(db *bun.DB, packageName string, ecosystem string) ([]uuid.UUID, error)
- func GetOsvUUIDsByOsvIds(db *bun.DB, osvIds []string) (map[string]uuid.UUID, error)
- func GetVulnerabilitiesForPackage(db *bun.DB, packageName string, ecosystem string) ([]knowledge.PackageVulnerability, error)
- func GetVulnerabilitiesForPackages(db *bun.DB, packages []struct{ ... }) ([]knowledge.PackageVulnerability, error)
- func UpdateCWE(db *bun.DB, cwes []knowledge.CWEEntry) error
- func UpdateEPSS(db *bun.DB, epssScores []knowledge.EPSS) error
- func UpdateFriendsOfPHP(db *bun.DB, advisory knowledge.FriendsOfPHPAdvisory) error
- func UpdateLicenses(db *bun.DB, licenses []knowledge.License) error
- func UpdateNvd(db *bun.DB, nvd []knowledge.NVDItem) error
- func UpdateOsv(db *bun.DB, osv knowledge.OSVItem) error
- func UpdatePackage(db *bun.DB, pack knowledge.Package) error
- type OptimizedPackageManager
- type PerformanceStats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BatchInsertFriendsOfPhpPackageVulnerabilities ¶
func BatchInsertFriendsOfPhpPackageVulnerabilities(db *bun.DB, items []knowledge.PackageVulnerability) error
BatchInsertFriendsOfPhpPackageVulnerabilities inserts FriendsOfPHP-based package-vulnerability links.
func BatchInsertNvdPackageVulnerabilities ¶
func BatchInsertNvdPackageVulnerabilities(db *bun.DB, items []knowledge.PackageVulnerability) error
BatchInsertNvdPackageVulnerabilities inserts NVD-based package-vulnerability links.
func BatchInsertOsvPackageVulnerabilities ¶
func BatchInsertOsvPackageVulnerabilities(db *bun.DB, items []knowledge.PackageVulnerability) error
BatchInsertOsvPackageVulnerabilities inserts OSV-based package-vulnerability links.
func BatchUpdateFriendsOfPHP ¶
func BatchUpdateFriendsOfPHP(db *bun.DB, advisories []knowledge.FriendsOfPHPAdvisory) error
BatchUpdateFriendsOfPHP performs efficient batch upsert operations for multiple FriendsOfPHP advisories
func BatchUpdateOsv ¶
BatchUpdateOsv performs efficient batch upsert operations for multiple OSV records. This is significantly more efficient than individual updates when processing many records.
func GetAllFriendsOfPHP ¶
GetAllFriendsOfPHP retrieves all FriendsOfPHP advisories with optional pagination
func GetFriendsOfPHPByAdvisoryID ¶
func GetFriendsOfPHPByAdvisoryID(db *bun.DB, advisoryId string) (*knowledge.FriendsOfPHPAdvisory, error)
GetFriendsOfPHPByAdvisoryID retrieves a FriendsOfPHP advisory by its advisory ID
func GetFriendsOfPHPByPackage ¶
func GetFriendsOfPHPByPackage(db *bun.DB, packageName string) ([]knowledge.FriendsOfPHPAdvisory, error)
GetFriendsOfPHPByPackage retrieves FriendsOfPHP advisories for a specific Composer package
func GetFriendsOfPhpUUIDsByAdvisoryIds ¶
func GetFriendsOfPhpUUIDsByAdvisoryIds(db *bun.DB, advisoryIds []string) (map[string]uuid.UUID, error)
GetFriendsOfPhpUUIDsByAdvisoryIds retrieves the internal UUIDs for a list of FriendsOfPHP advisory IDs. Returns a map from advisory_id (string) to internal UUID.
func GetNvdUUIDsByNvdIds ¶
GetNvdUUIDsByNvdIds retrieves the internal UUIDs for a list of NVD IDs. Returns a map from nvd_id (string like "CVE-xxx") to internal UUID.
func GetOsvByID ¶
GetOsvByID retrieves an OSV record by its OSV ID.
func GetOsvIdsForPackage ¶
GetOsvIdsForPackage retrieves OSV UUIDs for a specific package.
func GetOsvUUIDsByOsvIds ¶
GetOsvUUIDsByOsvIds retrieves the internal UUIDs for a list of OSV IDs. Returns a map from osv_id (string like "GHSA-xxx") to internal UUID.
func GetVulnerabilitiesForPackage ¶
func GetVulnerabilitiesForPackage(db *bun.DB, packageName string, ecosystem string) ([]knowledge.PackageVulnerability, error)
GetVulnerabilitiesForPackage retrieves all vulnerability links for a specific package.
func GetVulnerabilitiesForPackages ¶
func GetVulnerabilitiesForPackages(db *bun.DB, packages []struct { Name string Ecosystem string }) ([]knowledge.PackageVulnerability, error)
GetVulnerabilitiesForPackages retrieves vulnerability links for multiple packages.
func UpdateCWE ¶
UpdateCWE updates the CWE (Common Weakness Enumeration) entries in the graph database. It takes a graph driver and a slice of CWEEntry structs as input. For each CWEEntry in the slice, it tries to update the corresponding document in the "CWE" vertex collection. If the document exists and is successfully updated, it generates a changelog and creates a new document in the "REVISIONS" vertex collection. If the document doesn't exist, it creates a new document in the "CWE" vertex collection. Returns an error if any operation fails.
func UpdateEPSS ¶
UpdateCWE updates the CWE (Common Weakness Enumeration) entries in the graph database. It takes a graph driver and a slice of CWEEntry structs as input. For each CWEEntry in the slice, it tries to update the corresponding document in the "CWE" vertex collection. If the document exists and is successfully updated, it generates a changelog and creates a new document in the "REVISIONS" vertex collection. If the document doesn't exist, it creates a new document in the "CWE" vertex collection. Returns an error if any operation fails.
func UpdateFriendsOfPHP ¶
func UpdateFriendsOfPHP(db *bun.DB, advisory knowledge.FriendsOfPHPAdvisory) error
UpdateFriendsOfPHP updates or inserts a FriendsOfPHP advisory using an efficient upsert operation
func UpdateOsv ¶
UpdateOsv updates or inserts an OSV document using an efficient upsert operation. This replaces the inefficient check-then-act pattern with a single atomic operation.
func UpdatePackage ¶
UpdatePackage updates a package in the specified graph with the given package information. It takes the graph, package details, and language as input parameters. If the package key is empty, it returns an error. If the package already exists in the graph, it updates the package and creates a revision document with the changelog. If the package doesn't exist, it creates a new package document. It also updates the versions of the package and creates edge documents to link the package with its versions. Returns an error if any operation fails.
Types ¶
type OptimizedPackageManager ¶
type OptimizedPackageManager struct {
// contains filtered or unexported fields
}
Optimized connection pool and prepared statement management
func NewOptimizedPackageManager ¶
func NewOptimizedPackageManager(db *bun.DB) *OptimizedPackageManager
NewOptimizedPackageManager creates a new optimized package manager with connection pooling
func (*OptimizedPackageManager) BatchUpdatePackages ¶
func (opm *OptimizedPackageManager) BatchUpdatePackages(packages []knowledge.Package) error
BatchUpdatePackages performs optimized batch updates with prepared statements and transactions
func (*OptimizedPackageManager) GetStats ¶
func (opm *OptimizedPackageManager) GetStats() PerformanceStats
GetStats returns performance statistics for the optimized package manager
func (*OptimizedPackageManager) PrintPerformanceReport ¶
func (opm *OptimizedPackageManager) PrintPerformanceReport()
PrintPerformanceReport prints a detailed performance report