store

package
v0.32.2 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: MIT Imports: 7 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package store provides the entities, indexes and BSON codec used by the mongo persistence example.

Index

Constants

View Source
const DateTimeLayout = "2006-01-02T15:04:05.000Z0700"

DateTimeLayout is the ISO 8601 layout with millisecond precision.

Variables

View Source
var (
	EntityIndex = mongo.IndexModel{
		Keys: bson.D{
			{Key: "id", Value: 1},
		},
		Options: options.Index().SetUnique(true),
	}
)

EntityIndex is a unique index on the id field.

View Source
var (
	EntityWithVersionsIndex = mongo.IndexModel{
		Keys: bson.D{
			{Key: "id", Value: 1},
			{Key: "version", Value: 1},
		},
		Options: options.Index().SetUnique(true),
	}
)

EntityWithVersionsIndex is a unique index on the id and version fields.

View Source
var (
	TDateTime = reflect.TypeFor[DateTime]()
)

TDateTime is the reflect type of DateTime.

Functions

This section is empty.

Types

type DateTime

type DateTime string

DateTime is a time formatted with DateTimeLayout.

func NewDateTime

func NewDateTime(t time.Time) DateTime

NewDateTime returns t formatted as DateTime.

func (DateTime) MustTime

func (d DateTime) MustTime() time.Time

MustTime is like Time but panics on failure.

func (DateTime) String

func (d DateTime) String() string

String returns the string representation.

func (DateTime) Time

func (d DateTime) Time() (time.Time, error)

Time parses the date time into a time.Time.

type DateTimeCodec

type DateTimeCodec struct{}

DateTimeCodec encodes DateTime values as BSON datetimes and decodes them from BSON datetimes or strings.

func (*DateTimeCodec) DecodeValue

func (d *DateTimeCodec) DecodeValue(_ bson.DecodeContext, vr bson.ValueReader, val reflect.Value) error

DecodeValue reads a BSON datetime or string into val.

func (*DateTimeCodec) EncodeValue

func (d *DateTimeCodec) EncodeValue(_ bson.EncodeContext, vw bson.ValueWriter, val reflect.Value) error

EncodeValue writes val as a BSON datetime.

type Dummy

type Dummy struct {
	Entity               `json:",inline" bson:",inline"`
	EntityWithVersions   `json:",inline" bson:",inline"`
	EntityWithTimestamps `json:",inline" bson:",inline"`
}

Dummy is an example entity with an ID, a version and timestamps.

type Entity

type Entity struct {
	ID     string        `json:"id" bson:"id" yaml:"id"`
	BsonID bson.ObjectID `json:"_id,omitempty" bson:"_id,omitempty" yaml:"_id,omitempty"` //nolint:tagliatelle
}

Entity holds the ID and the MongoDB object ID of a document.

func NewEntity

func NewEntity(id string) Entity

NewEntity returns an Entity with the given id.

func (*Entity) GetID

func (e *Entity) GetID() string

GetID returns the ID.

func (*Entity) SetID

func (e *Entity) SetID(value string)

SetID sets the ID.

type EntityWithTimestamps

type EntityWithTimestamps struct {
	CreatedAt time.Time `json:"createdAt" bson:"createdAt"  yaml:"createdAt"`
	UpdatedAt time.Time `json:"updatedAt" bson:"updatedAt"  yaml:"updatedAt"`
}

EntityWithTimestamps holds the creation and update times of a document.

func (*EntityWithTimestamps) GetCreatedAt

func (e *EntityWithTimestamps) GetCreatedAt() time.Time

GetCreatedAt returns the creation time.

func (*EntityWithTimestamps) GetUpdatedAt

func (e *EntityWithTimestamps) GetUpdatedAt() time.Time

GetUpdatedAt returns the update time.

func (*EntityWithTimestamps) SetCreatedAt

func (e *EntityWithTimestamps) SetCreatedAt(t time.Time)

SetCreatedAt sets the creation time.

func (*EntityWithTimestamps) SetUpdatedAt

func (e *EntityWithTimestamps) SetUpdatedAt(t time.Time)

SetUpdatedAt sets the update time.

type EntityWithVersions

type EntityWithVersions struct {
	Version uint32 `json:"version" bson:"version"  yaml:"version"`
}

EntityWithVersions holds the version of a document used to detect dirty writes.

func (*EntityWithVersions) GetVersion

func (e *EntityWithVersions) GetVersion() uint32

GetVersion returns the version.

func (*EntityWithVersions) IncreaseVersion

func (e *EntityWithVersions) IncreaseVersion() uint32

IncreaseVersion increments the version and returns it.

func (*EntityWithVersions) SetVersion

func (e *EntityWithVersions) SetVersion(value uint32)

SetVersion sets the version.

Jump to

Keyboard shortcuts

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