wrap: github.com/lucacasonato/wrap Index | Files | Directories

package wrap

import "github.com/lucacasonato/wrap"

Index

Package Files

bulk.go collection.go collectionquery.go connect.go database.go document.go indexes.go iterator.go transactions.go wrap.go

type BulkCollection Uses

type BulkCollection struct {
    ID         string
    Collection *Collection
    // contains filtered or unexported fields
}

BulkCollection is a collection which is used for bulk writing

func (*BulkCollection) Add Uses

func (c *BulkCollection) Add(data interface{})

Add a document with a certain value

func (*BulkCollection) DeleteDocumentsWhere Uses

func (c *BulkCollection) DeleteDocumentsWhere(filter filter.Filter)

DeleteDocumentsWhere the filter matches

func (*BulkCollection) Document Uses

func (c *BulkCollection) Document(id string) *BulkDocument

Document get a single document from a collection

func (*BulkCollection) UpdateDocumentsWhere Uses

func (c *BulkCollection) UpdateDocumentsWhere(filter filter.Filter, upsert bool, updates ...update.Update) error

UpdateDocumentsWhere the filter matches

type BulkDocument Uses

type BulkDocument struct {
    ID         string
    Collection *BulkCollection
}

BulkDocument is a document which is used for bulk writing

func (*BulkDocument) Delete Uses

func (d *BulkDocument) Delete() error

Delete a document from a collection

func (*BulkDocument) Set Uses

func (d *BulkDocument) Set(data interface{}) error

Set a document to a certain value

func (*BulkDocument) Update Uses

func (d *BulkDocument) Update(upsert bool, updates ...update.Update) error

Update a document using the update operators

type Client Uses

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

Client wraps the mongo client

func Connect Uses

func Connect(mongoURI string, timeout time.Duration) (*Client, error)

Connect to a mongo instance

func (*Client) Database Uses

func (c *Client) Database(id string) *Database

Database gets a database instance from a client

func (*Client) Transaction Uses

func (c *Client) Transaction(run func(client *Client) error) error

Transaction means all operations executed in the run function are atomic

type Collection Uses

type Collection struct {
    ID  string

    Database *Database
    // contains filtered or unexported fields
}

Collection is a collection on the database

func (*Collection) Add Uses

func (c *Collection) Add(data interface{}) (*Document, error)

Add a document with a certain value

func (*Collection) All Uses

func (c *Collection) All() *CollectionQuery

All returns an abstract of the collection of all documents

func (*Collection) Bulk Uses

func (c *Collection) Bulk(run func(collection *BulkCollection) error, ordered bool) error

Bulk is used to do bulk writes

func (*Collection) CreateIndex Uses

func (c *Collection) CreateIndex(fields map[string]Index) error

CreateIndex for a single or group of fields

func (*Collection) Delete Uses

func (c *Collection) Delete() error

Delete a collection

func (*Collection) DeleteDocumentsWhere Uses

func (c *Collection) DeleteDocumentsWhere(filter filter.Filter) error

DeleteDocumentsWhere the filter matches

func (*Collection) Document Uses

func (c *Collection) Document(id string) *Document

Document get a single document from a collection

func (*Collection) Transaction Uses

func (c *Collection) Transaction(run func(c *Collection) error) error

Transaction means all operations executed in the run function are atomic

func (*Collection) UpdateDocumentsWhere Uses

func (c *Collection) UpdateDocumentsWhere(filter filter.Filter, upsert bool, updates ...update.Update) error

UpdateDocumentsWhere the filter matches

func (*Collection) Where Uses

func (c *Collection) Where(filter filter.Filter) *CollectionQuery

Where returns an abstract of the collection of documents that match the filter

type CollectionQuery Uses

type CollectionQuery struct {
    Collection *Collection
    // contains filtered or unexported fields
}

CollectionQuery is a filtered abstraction of a group of documents

func (*CollectionQuery) AddFields Uses

func (cq *CollectionQuery) AddFields(spec map[string]interface{}) *CollectionQuery

AddFields adds some fields to the returned documents

func (*CollectionQuery) Count Uses

func (cq *CollectionQuery) Count(field string) *CollectionQuery

Count returns the amount of documents in a single document under the field 'field'

func (*CollectionQuery) DocumentIterator Uses

func (cq *CollectionQuery) DocumentIterator() (*Iterator, error)

DocumentIterator gives you an iterator to loop over the documents

func (*CollectionQuery) Join Uses

func (cq *CollectionQuery) Join(localField string, foreignCollection string, foreignField string, as string) *CollectionQuery

Join gets all documents from a foreign collection in this database, filters them by checking if the value of foreignField matches the value of localField and if so adding these to the original document as an array under the 'as' key

func (*CollectionQuery) Limit Uses

func (cq *CollectionQuery) Limit(n int) *CollectionQuery

Limit to only return n documents

func (*CollectionQuery) Modify Uses

func (cq *CollectionQuery) Modify(spec map[string]interface{}) *CollectionQuery

Modify changes the data structure of the field like specified by the specification

func (*CollectionQuery) Sample Uses

func (cq *CollectionQuery) Sample(n int) *CollectionQuery

Sample returns n amount of documents randomly picked from the document pool

func (*CollectionQuery) Skip Uses

func (cq *CollectionQuery) Skip(n int) *CollectionQuery

Skip skips the first n documents

func (*CollectionQuery) Sort Uses

func (cq *CollectionQuery) Sort(sorters ...*Sorter) *CollectionQuery

Sort sorts a collection by a certain order

func (*CollectionQuery) Transaction Uses

func (cq *CollectionQuery) Transaction(run func(cq *CollectionQuery) error) error

Transaction means all operations executed in the run function are atomic

type Database Uses

type Database struct {
    ID  string

    Client *Client
    // contains filtered or unexported fields
}

Database is a database instance

func (*Database) Collection Uses

func (d *Database) Collection(id string) *Collection

Collection in the database by id

func (*Database) Delete Uses

func (d *Database) Delete() error

Delete a database

func (*Database) Transaction Uses

func (db *Database) Transaction(run func(db *Database) error) error

Transaction means all operations executed in the run function are atomic

type Document Uses

type Document struct {
    ID         string
    Collection *Collection
}

Document is a document in a collection

func (*Document) Delete Uses

func (d *Document) Delete() error

Delete a document from a collection

func (*Document) Get Uses

func (d *Document) Get() (*DocumentData, error)

Get the contents of a document

func (*Document) Set Uses

func (d *Document) Set(data interface{}) error

Set a document to a certain value

func (*Document) Transaction Uses

func (d *Document) Transaction(run func(d *Document) error) error

Transaction means all operations executed in the run function are atomic

func (*Document) Update Uses

func (d *Document) Update(upsert bool, updates ...update.Update) error

Update a document using the update operators

type DocumentData Uses

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

DocumentData is the data in a document

func (*DocumentData) Data Uses

func (d *DocumentData) Data() (interface{}, error)

Data decodes some data and returns an interface

func (*DocumentData) DataTo Uses

func (d *DocumentData) DataTo(data interface{}) error

DataTo decodes some data into an interface

type Index Uses

type Index interface{}

Index used to index data

var (
    // AscendingIndex goes from start to end
    AscendingIndex Index = 1
    // DescendingIndex goes from end to start
    DescendingIndex Index = -1
    // TextIndex indexes text
    TextIndex Index = "text"
)

type Iterator Uses

type Iterator struct {
    Collection *Collection
    // contains filtered or unexported fields
}

Iterator to iterate over documents

func (*Iterator) Close Uses

func (i *Iterator) Close() error

Close stops the iterator

func (*Iterator) Data Uses

func (i *Iterator) Data() (interface{}, error)

Data decodes some data and returns an interface

func (*Iterator) DataTo Uses

func (i *Iterator) DataTo(data interface{}) error

DataTo decodes some data into an interface

func (*Iterator) ID Uses

func (i *Iterator) ID() string

ID gets the ID of the current iterator item

func (*Iterator) Next Uses

func (i *Iterator) Next() bool

Next means go to the next document in the iterator

type Sorter Uses

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

Sorter is for sorting

func Ascending Uses

func Ascending(field string) *Sorter

Ascending means sorted from small to big

func Descending Uses

func Descending(field string) *Sorter

Descending means sorted from big to small

Directories

PathSynopsis
example
expressions
filter
types
update

Package wrap imports 9 packages (graph) and is imported by 2 packages. Updated 2019-11-09. Refresh now. Tools for package owners.