Documentation ¶
Overview ¶
Package metafield defines and provide functions on custom meta fields for the schema.
Meta fields are those fields that tracks extra information about the document which can be helpful to determine the state of a document.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var CreatedAtField = newCreatedAtMetaField()
CreatedAtField is the meta field that stores the timestamp of the document creation. This field is automatically added (if not present in the input) to the schema if the schemaopt.SchemaOptions.Timestamps is set to true. The value of this field is set to the current timestamp in ISO format.
var DocVersionField = newDocVersionMetaField()
DocVersionField is the meta field that stores the version of the document. This field is automatically added (if not present in the input) to the schema if the schemaopt.SchemaOptions.VersionKey is set to true. This field starts with a default value of 0.
var UpdatedAtField = newUpdatedAtMetaField()
UpdatedAtField is the meta field that stores the timestamp of the document updation. This field is automatically added (if not present in the input) to the schema if the schemaopt.SchemaOptions.Timestamps is set to true. The value of this field is set to the current timestamp in ISO format and is updated every time the document is updated.
Functions ¶
func AddMetaFields ¶
func AddMetaFields(bsonDoc *bson.D, schemaOptions schemaopt.SchemaOptions) error
AddMetaFields adds all applicable meta fields to the bson doc based on the provided schema options.
Types ¶
type MetaField ¶
type MetaField interface { // GetKey returns the unique key of the meta field. GetKey() MetaFieldKey // GetReflectKind returns the reflect kind of the meta field. GetReflectKind() reflect.Kind // GetApplicableTransformers returns the list of transformers applicable for the meta field. // Meta fields are added to the bson doc before calling the BuildBSONDoc method which transforms the doc. GetApplicableTransformers() []transformer.Transformer // IsApplicable returns true if the meta field is applicable for the given schema options. // Meta field is processed against the doc only if it is applicable. IsApplicable(schemaOptions schemaopt.SchemaOptions) bool // CheckIfValidValue validates the type of the provided value against the expected type. CheckIfValidValue(val interface{}) bool // FieldAlreadyPresent modifies the doc at the provided index if the field is already present in the doc // and is of the expected type. FieldAlreadyPresent(doc *bson.D, index int) // FieldPresentWithIncorrectVal modifies the doc at the provided index if the field is already present in the doc // but is not of the expected type. FieldPresentWithIncorrectVal(doc *bson.D, index int) error // FieldNotPresent appends the missing field in the doc. FieldNotPresent(doc *bson.D) }
func GetAvailableMetaFields ¶ added in v0.2.0
func GetAvailableMetaFields() []MetaField
GetAvailableMetaFields returns the list of available meta fields.
type MetaFieldKey ¶
type MetaFieldKey string
MetaFieldKey is the unique field name of a meta field.
const ( MetaFieldKeyCreatedAt MetaFieldKey = "createdAt" MetaFieldKeyUpdatedAt MetaFieldKey = "updatedAt" MetaFieldKeyDocVersion MetaFieldKey = "__v" )