timestamps

package
v0.3.0-beta0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// Precision is the effective precision of timestamps.
	// Currently it's 1 microsecond as it's what Datastore supports.
	// Datastore: 1 microsecond: https://cloud.google.com/datastore/docs/concepts/entities#date_and_time
	Precision = time.Microsecond
)

Variables

This section is empty.

Functions

func LoadUUID

func LoadUUID(ps []datastore.Property, name string) (uuid.UUID, []datastore.Property, error)

func TimeToProto

func TimeToProto(t time.Time) *timestamppb.Timestamp

TimeToProto converts time.Time to timestamppb.Timestamp. If t is zero, it returns nil.

func UUIDToDatastoreProperty

func UUIDToDatastoreProperty(name string, u uuid.UUID, noIndex bool) datastore.Property

Types

type Timestamps

type Timestamps struct {
	// CreatedAt is the timestamp of the record creation time
	// Automatically set by MetaDB
	CreatedAt time.Time `datastore:",noindex"`
	// UpdatedAt is the timestamp of the last modification time
	// Automatically set and managed by MetaDB
	UpdatedAt time.Time `datastore:",noindex"`
	// Signature is a UUID that is randomly created each time the record is updated
	// Automatically set and managed by MetaDB
	Signature uuid.UUID `datastore:"-"`
}

Timestamps keeps keeps when each record is created or updated as well as a randomly generated UUID to keep consistency under concurrent writes. It should be embedded to metadata entities such as Record and Store.

func New

func New() Timestamps

New returns a new Timestamps instance with CreatedAt and UpdatedAt set to time.Now() and Signature set to uuid.New().

func (*Timestamps) Load

func (t *Timestamps) Load(ps []datastore.Property) error

Load implements the Datastore PropertyLoadSaver interface and converts Datastore properties to corresponding struct fields.

func (*Timestamps) Save

func (t *Timestamps) Save() ([]datastore.Property, error)

Save implements the Datastore PropertyLoadSaver interface and converts the properties field in the struct to separate Datastore properties.

func (*Timestamps) Update

func (t *Timestamps) Update()

Update updates the UpdatedAt and Signature fields with time.Now() and uuid.New().

Jump to

Keyboard shortcuts

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