datastore

package
v0.0.0-...-e560ebb Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2021 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InvalidPageToken string = "Invalid Page Token."
	AlreadyExists    string = "Entity already exists."
	NotFound         string = "Entity not found"
	InternalError    string = "Internal Server Error."
	CannotDelete     string = "cannot be deleted"
	InvalidArgument  string = "Invalid argument"
	PermissionDenied string = "PermissionDenied"
)

Error messages for datastore operations

Variables

This section is empty.

Functions

func BatchDelete

func BatchDelete(ctx context.Context, es []proto.Message, nf NewFunc) error

BatchDelete removes the entities from the datastore

This is a non-atomic operation Returns error even if partial delete succeeds. Must be used within a Transaction so that partial deletes are rolled back. Using it in a Transaction will rollback the partial deletes and propagate correct error message.

func BatchGet

func BatchGet(ctx context.Context, es []proto.Message, nf NewFunc, getID GetIDFunc) ([]proto.Message, error)

BatchGet returns all entities in table for given IDs.

func Delete

func Delete(ctx context.Context, pm proto.Message, nf NewFunc) error

Delete deletes the entity from the datastore.

func Exists

func Exists(ctx context.Context, entities []FleetEntity) ([]bool, error)

Exists checks if a list of fleet entities exist in datastore.

func Get

func Get(ctx context.Context, pm proto.Message, nf NewFunc) (proto.Message, error)

Get retrieves entity from the datastore.

func GetOSIndex

func GetOSIndex(osversion string) []string

GetOSIndex returns a slics of strings for a given string

func GetServoID

func GetServoID(servoHostname string, servoPort int32) string

GetServoID returns the servo_id for searching

func ListQuery

func ListQuery(ctx context.Context, entityKind string, pageSize int32, pageToken string, filterMap map[string][]interface{}, keysOnly bool) (q *datastore.Query, err error)

ListQuery constructs a query to list entities with pagination

func Put

func Put(ctx context.Context, pm proto.Message, nf NewFunc, update bool) (proto.Message, error)

Put either creates or updates an entity in the datastore

func PutAll

func PutAll(ctx context.Context, pms []proto.Message, nf NewFunc, update bool) ([]proto.Message, error)

PutAll Upserts entities in the datastore. This is a non-atomic operation and doesnt check if the object already exists before insert/update. Returns error even if partial insert/updates succeeds. Must be used within a Transaction where objects are checked for existence before update/insert. Using it in a Transaction will rollback the partial insert/updates and propagate correct error message.

func PutSingle

func PutSingle(ctx context.Context, pm proto.Message, nf NewFunc) (proto.Message, error)

PutSingle upserts a single entity in the datastore.

If you have a clean intention to create or update an entity, please use Put(). This function doesn't need to be called in a transaction.

Types

type FleetEntity

type FleetEntity interface {
	GetProto() (proto.Message, error)
}

FleetEntity represents the interface of entity in datastore.

type GetIDFunc

type GetIDFunc func(pm proto.Message) string

GetIDFunc gets the id of a fleet entity

type NewFunc

type NewFunc func(context.Context, proto.Message) (FleetEntity, error)

NewFunc creates a new fleet entity.

type OpResult

type OpResult struct {
	// Operations:
	// Get: record the retrieved proto object.
	// Add: record the proto object to be added.
	// Delete: record the proto object to be deleted.
	// Update: record the proto object to be updated.
	Data proto.Message
	Err  error
}

OpResult records the result of datastore operations

func (*OpResult) LogError

func (op *OpResult) LogError(e error)

LogError logs the error for an operation.

type OpResults

type OpResults []*OpResult

OpResults is a list of OpResult.

func DeleteAll

func DeleteAll(ctx context.Context, es []proto.Message, nf NewFunc) *OpResults

DeleteAll removes the entities from the datastore

func GetAll

func GetAll(ctx context.Context, qf QueryAllFunc) (*OpResults, error)

GetAll returns all entities in table.

func Insert

func Insert(ctx context.Context, es []proto.Message, nf NewFunc, update, upsert bool) (*OpResults, error)

Insert inserts the fleet objects.

func (OpResults) Failed

func (rs OpResults) Failed() OpResults

Failed generates the list of entities failed the operation.

func (OpResults) Passed

func (rs OpResults) Passed() OpResults

Passed generates the list of entities passed the operation.

type QueryAllFunc

type QueryAllFunc func(context.Context) ([]FleetEntity, error)

QueryAllFunc queries all entities for a given table.

Jump to

Keyboard shortcuts

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