document

package
v2.0.0-alpha.3 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2023 License: MIT Imports: 6 Imported by: 4

Documentation

Index

Constants

View Source
const (
	ObjectIdField  = "_id"
	ExpiresAtField = "_expiresAt"
)

Variables

This section is empty.

Functions

func Encode

func Encode(doc *Document) ([]byte, error)

func Validate

func Validate(doc *Document) error

Types

type Document

type Document struct {
	// contains filtered or unexported fields
}

Document represents a document as a map.

func Decode

func Decode(data []byte) (*Document, error)

func NewDocument

func NewDocument() *Document

NewDocument creates a new empty document.

func NewDocumentOf

func NewDocumentOf(o interface{}) *Document

NewDocumentOf creates a new document and initializes it with the content of the provided object. It returns nil if the object cannot be converted to a valid Document.

func (*Document) AsMap

func (doc *Document) AsMap() map[string]interface{}

func (*Document) Copy

func (doc *Document) Copy() *Document

Copy returns a shallow copy of the underlying document.

func (*Document) ExpiresAt

func (doc *Document) ExpiresAt() *time.Time

ExpiresAt returns the document expiration instant

func (*Document) Fields

func (doc *Document) Fields(includeSubFields bool) []string

Fields returns a lexicographically sorted slice of all available field names in the document. Nested fields, if included, are represented using dot notation.

func (*Document) Get

func (doc *Document) Get(name string) interface{}

Get retrieves the value of a field. Nested fields can be accessed using dot.

func (*Document) Has

func (doc *Document) Has(name string) bool

Has tells returns true if the document contains a field with the supplied name.

func (*Document) ObjectId

func (doc *Document) ObjectId() string

ObjectId returns the id of the document, provided that the document belongs to some collection. Otherwise, it returns the empty string.

func (*Document) Set

func (doc *Document) Set(name string, value interface{})

Set maps a field to a value. Nested fields can be accessed using dot.

func (*Document) SetAll

func (doc *Document) SetAll(values map[string]interface{})

SetAll sets each field specified in the input map to the corresponding value. Nested fields can be accessed using dot.

func (*Document) SetExpiresAt

func (doc *Document) SetExpiresAt(expiration time.Time)

ExpiresAt sets document expiration

func (*Document) TTL

func (doc *Document) TTL() time.Duration

TTL returns a duration representing the time to live of the document before expiration. A negative duration means that the document has no expiration, while a zero value represents an already expired document.

func (*Document) ToMap

func (doc *Document) ToMap() map[string]interface{}

GetAll returns a map of all available fields in the document. Nested fields are represented by sub-maps. This is a deep copy, but values are note cloned.

func (*Document) Unmarshal

func (doc *Document) Unmarshal(v interface{}) error

Unmarshal stores the document in the value pointed by v.

Jump to

Keyboard shortcuts

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