Documentation ¶
Index ¶
- Constants
- Variables
- type DB
- type Document
- func (d *Document) Decode(data []byte) error
- func (d *Document) Encode() ([]byte, error)
- func (d *Document) ExpiresAt() *time.Time
- func (d *Document) Fields(withSubFields bool) []string
- func (d *Document) Get(key string) interface{}
- func (d *Document) Has(key string) bool
- func (d *Document) IsValid() error
- func (d *Document) Map() map[string]interface{}
- func (d *Document) Marshal(from interface{}) error
- func (d *Document) ObjectId() (string, error)
- func (d *Document) Set(key string, val interface{}) error
- func (d *Document) SetExpiresAt(exp time.Time) error
- func (d *Document) Unmarshal(to interface{}) error
- func (d *Document) Update(updates map[string]interface{}, upsert bool) error
- type TransactionFunc
Constants ¶
const ( ObjectIdField = "_id" ExpiresAtField = "_expiresAt" )
Variables ¶
Functions ¶
This section is empty.
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
func (*DB) CreateCollection ¶
Create a collection in the database
func (*DB) DropCollection ¶
Remove a collection from the database, removing all documents
type Document ¶
type Document struct {
// contains filtered or unexported fields
}
Represents a document in a collection
func NewDocument ¶
func NewDocument() *Document
Create a new empty document. User must add _id and _expiresAt themselves.
It will be validated when being used
func NewDocumentFrom ¶
Create a new document initialized from an object.
Please use maps, or else it will return an error
func (*Document) Decode ¶
Decodes the byte arrays into the document.
Will resets all of the document's existing fields and values
func (*Document) Get ¶
Returns the value associated with a key inside the document. It returns nil if the key is not found, or the value is nil
func (*Document) Marshal ¶
Takes in an interface and marshal it into the current document
Will resets all of the document's existing fields and values
func (*Document) ObjectId ¶
Returns the document ID.
- ErrIdNotFound if the ID is not found (key is "_id").
- ErrInvalidId if the ID has an invalid type (must be string)
func (*Document) Set ¶
Set a value to a key inside the document. By default, it overrides the existing value associated to the key and also add a new key if key does not exist
func (*Document) SetExpiresAt ¶
Set the expiration date of this document
type TransactionFunc ¶
type TransactionFunc = func(tx store.Transaction) error