entities

package
v0.0.0-...-6070400 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2025 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package entities contains the datastore entities and handles datestore manipulation.

Index

Constants

View Source
const CachedCostResultKind = "CachedCostResultKind"

CachedCostResultKind is the datastore type for a cached DUT.

View Source
const CostIndicatorKind = "CostIndicatorKind"

CostIndicatorKind is the datastore kind of a cost indicator entity.

Variables

This section is empty.

Functions

func ApplyFilter

func ApplyFilter(query *datastore.Query, filter *fleetcostAPI.ListCostIndicatorsFilter) (*datastore.Query, error)

ApplyFilter applies filters to a datastore query and returns it.

func DeleteCostIndicatorEntity

func DeleteCostIndicatorEntity(ctx context.Context, entity *CostIndicatorEntity) error

DeleteCostIndicatorEntity deletes a cost indicator entity.

func ListCostIndicators

func ListCostIndicators(ctx context.Context, limit int, filter *fleetcostAPI.ListCostIndicatorsFilter) ([]*fleetcostpb.CostIndicator, error)

ListCostIndicators lists the cost indicators in the database, up to a limit (not yet implemented).

Types

type CachedCostResultEntity

type CachedCostResultEntity struct {

	// The hostname or DeviceID are the two fields that are
	// useful for looking up a device.
	Hostname string `gae:"hostname"`
	DeviceID string `gae:"deviceid"`
	// ExpirationTime is the time that the cache entry is no longer valid.
	ExpirationTime time.Time               `gae:"expiration_time"`
	CostResult     *fleetcostpb.CostResult `gae:"cost_result"`
	// deprecated! Do not use.
	CostReport *fleetcostpb.CostReport `gae:"cost_report"`
	// contains filtered or unexported fields
}

CachedCostResultEntity is the datastore type for cached DUT cost.

func (*CachedCostResultEntity) GetAllMeta

func (entity *CachedCostResultEntity) GetAllMeta() datastore.PropertyMap

GetAllMeta returns all the meta keys. Just use the default implementation, it's fine.

func (*CachedCostResultEntity) GetMeta

func (entity *CachedCostResultEntity) GetMeta(key string) (any, bool)

GetMeta gets a meta key. Compute the ID, fall back to the default implementation.

Use the entity and the hostname in order as the ID. This isn't IDeal (get it?) because we're realistically just using one or the other.

func (*CachedCostResultEntity) Load

func (entity *CachedCostResultEntity) Load(propertyMap datastore.PropertyMap) error

Load loads an entity.

func (*CachedCostResultEntity) Save

func (entity *CachedCostResultEntity) Save(withMeta bool) (datastore.PropertyMap, error)

Save saves an entity.

func (*CachedCostResultEntity) SetMeta

func (entity *CachedCostResultEntity) SetMeta(key string, value any) bool

SetMeta always returns false. This communicates to the LUCI ORM that our meta keys cannot be changed.

This works better than not-implementing the method for reasons that I don't completely understand and don't really want to get into here.

type CostIndicatorEntity

type CostIndicatorEntity struct {
	Extra         datastore.PropertyMap      `gae:",extra"`
	CostIndicator *fleetcostpb.CostIndicator `gae:"cost_indicator"`
	// Indexed fields for improved query performance.
	Board               string  `gae:"board"`
	Model               string  `gae:"model"`
	Sku                 string  `gae:"sku"`
	Type                string  `gae:"type"`
	Location            string  `gae:"location"`
	AmortizationInYears float64 `gae:"amortization_in_years"`
	// contains filtered or unexported fields
}

CostIndicatorEntity is a datastore entity storing a cost indicator.

TODO(gregorynisbet): Change the name of the database entries from the legacy names Board, Model, Sku to the new ones.

func GetCostIndicatorEntity

func GetCostIndicatorEntity(ctx context.Context, entity *CostIndicatorEntity) (*CostIndicatorEntity, error)

GetCostIndicatorEntity extracts a cost indicator from the database.

func NewCostIndicatorEntity

func NewCostIndicatorEntity(costIndicator *fleetcostpb.CostIndicator) *CostIndicatorEntity

NewCostIndicatorEntity makes a cost indicator entity from an object extracted from a request.

func UpdateCostIndicatorEntity

func UpdateCostIndicatorEntity(ctx context.Context, entity *CostIndicatorEntity, fields []string) (*CostIndicatorEntity, error)

UpdateCostIndicatorEntity extracts a cost indicator entity from the database and updates it.

func (CostIndicatorEntity) Clone

func (indicator CostIndicatorEntity) Clone() *CostIndicatorEntity

Clone produces a deep copy of a cost indicator.

This method intentionally takes a non-pointer receiver to perform a shallow copy, and then replaces a field to perform a deep copy.

I don't actually know whether I also need to copy the datastore.PropertyMap.

func (*CostIndicatorEntity) GetAllMeta

func (indicator *CostIndicatorEntity) GetAllMeta() datastore.PropertyMap

GetAllMeta transfers control to the default implementation of GetAllMeta. We need this function so that we can compute the ID.

func (*CostIndicatorEntity) GetMeta

func (indicator *CostIndicatorEntity) GetMeta(key string) (any, bool)

GetMeta gets meta-values. The id ("$id") is computed. The other things (like $kind, for instance) get their default values.

func (*CostIndicatorEntity) Load

func (indicator *CostIndicatorEntity) Load(propertyMap datastore.PropertyMap) error

Load loads an entity.

func (*CostIndicatorEntity) Save

func (indicator *CostIndicatorEntity) Save(withMeta bool) (datastore.PropertyMap, error)

Save saves an entity.

func (*CostIndicatorEntity) SetMeta

func (indicator *CostIndicatorEntity) SetMeta(key string, value any) bool

SetMeta always returns false because we do not allow meta keys to be changed and false communicates this to the LUCI datastore library.

Jump to

Keyboard shortcuts

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