example

package
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2016 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Schema = schema{
	Product: &schemaProduct{
		Status:    storable.NewField("status", "int"),
		CreatedAt: storable.NewField("createdat", "time.Time"),
		UpdatedAt: storable.NewField("updatedat", "time.Time"),
		Name:      storable.NewField("name", "string"),
		Price: &schemaProductPrice{
			Amount:   storable.NewField("price.amount", "float64"),
			Discount: storable.NewField("price.discount", "float64"),
		},
		Discount: storable.NewField("discount", "float64"),
		Url:      storable.NewField("url", "string"),
		Tags:     storable.NewField("tags", "string"),
	},
}

Functions

This section is empty.

Types

type Price

type Price struct {
	Amount   float64
	Discount float64
}

type Product

type Product struct {
	storable.Document `bson:",inline" collection:"products"`

	Status    Status
	CreatedAt time.Time
	UpdatedAt time.Time
	Name      string
	Price     Price

	Discount float64
	Url      string
	Tags     []string
}

func (*Product) BeforeInsert

func (p *Product) BeforeInsert() error

func (*Product) BeforeSave

func (p *Product) BeforeSave() error

type ProductQuery

type ProductQuery struct {
	storable.BaseQuery
}

func (*ProductQuery) FindById

func (q *ProductQuery) FindById(ids ...bson.ObjectId) *ProductQuery

FindById add a new criteria to the query searching by _id

type ProductResultSet

type ProductResultSet struct {
	storable.ResultSet
	// contains filtered or unexported fields
}

func (*ProductResultSet) All

func (r *ProductResultSet) All() ([]*Product, error)

All returns all documents on the resultset and close the resultset

func (*ProductResultSet) ForEach

func (r *ProductResultSet) ForEach(f func(*Product) error) error

ForEach iterates the resultset calling to the given function.

func (*ProductResultSet) Get

func (r *ProductResultSet) Get() (*Product, error)

Get returns the document retrieved with the Next method.

func (*ProductResultSet) Next

func (r *ProductResultSet) Next() (returned bool)

Next prepares the next result document for reading with the Get method.

func (*ProductResultSet) One

func (r *ProductResultSet) One() (*Product, error)

One returns the first document on the resultset and close the resultset

type ProductStore

type ProductStore struct {
	storable.Store
}

func NewProductStore

func NewProductStore(db *mgo.Database) *ProductStore

func (*ProductStore) Find

func (s *ProductStore) Find(query *ProductQuery) (*ProductResultSet, error)

Find performs a find on the collection using the given query.

func (*ProductStore) FindOne

func (s *ProductStore) FindOne(query *ProductQuery) (*Product, error)

FindOne performs a find on the collection using the given query returning the first document from the resultset.

func (*ProductStore) Insert

func (s *ProductStore) Insert(doc *Product) error

Insert insert the given document on the collection, trigger BeforeInsert and AfterInsert if any. Throws ErrNonNewDocument if doc is a non-new document.

func (*ProductStore) MustFind

func (s *ProductStore) MustFind(query *ProductQuery) *ProductResultSet

MustFind like Find but panics on error

func (*ProductStore) MustFindOne

func (s *ProductStore) MustFindOne(query *ProductQuery) *Product

MustFindOne like FindOne but panics on error

func (*ProductStore) New

func (s *ProductStore) New(name string, price Price, createdAt time.Time) (doc *Product, err error)

New returns a new instance of Product.

func (*ProductStore) Query

func (s *ProductStore) Query() *ProductQuery

Query return a new instance of ProductQuery.

func (*ProductStore) Save

func (s *ProductStore) Save(doc *Product) (updated bool, err error)

Save insert or update the given document on the collection using Upsert, trigger BeforeUpdate and AfterUpdate if the document is non-new and BeforeInsert and AfterInset if is new.

func (*ProductStore) Update

func (s *ProductStore) Update(doc *Product) error

Update update the given document on the collection, trigger BeforeUpdate and AfterUpdate if any. Throws ErrNewDocument if doc is a new document.

type Status

type Status int
const (
	Draft Status = iota
	Published
)

func (Status) AfterInsert

func (s Status) AfterInsert() error

func (*Status) BeforeInsert

func (s *Status) BeforeInsert() error

Jump to

Keyboard shortcuts

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