Documentation
¶
Overview ¶
Package store provides the entities, indexes and BSON codec used by the mongo persistence example.
Index ¶
Constants ¶
const DateTimeLayout = "2006-01-02T15:04:05.000Z0700"
DateTimeLayout is the ISO 8601 layout with millisecond precision.
Variables ¶
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.
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.
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 ¶
NewDateTime returns t formatted as DateTime.
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.
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.