db

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 20, 2026 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindMatch

func FindMatch[T any](in []T, pred func(T) bool) (T, bool)

FindMatch returns the first element of in for which pred is true, and whether one was found. It is the generic form of the per-domain "find the matching row in this slice" helpers (identity/absorbable/same-host lookups) so they need not each re-spell the loop.

func Preload

func Preload(database *gorm.DB, filts map[string]bool) *gorm.DB

Preload loads a database with the base clause.Associations preload plus every association named with a true value in filts (a false entry is skipped, so callers can gate a preload on a request flag). It is the map-driven form used when the set of associations is conditional; PreloadAll is the plainer variadic form for the unconditional case.

func PreloadAll

func PreloadAll(database *gorm.DB, names ...string) *gorm.DB

PreloadAll loads a database with the base clause.Associations preload plus each named association, unconditionally. It is the single place association preloading is expressed, so the per-domain servers do not each re-implement the clause.Associations + range loop.

func ScopeBySource

func ScopeBySource(query *gorm.DB, joinTable, objectFK, tool string) *gorm.DB

ScopeBySource restricts a query to the objects contributed by the named tool, via that object's provenance m2m join (e.g. "host_sources"/"host_id"). An empty tool is a no-op, so callers can thread a request's Source filter through unconditionally. It is the one-liner wrapper the per-domain servers share instead of each repeating the same Scopes(...) block.

func ToPBs

func ToPBs[O pbConvertible[P], P any](ctx context.Context, in []O) ([]*P, error)

ToPBs converts a slice of ORM rows to pointers to their protobuf twins, returning the first conversion error rather than swallowing it. It replaces the identical ORM→PB range loop the domain servers each hand-rolled (and which discarded the ToPB error with `pb, _ :=`).

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL