item

package
v0.4.8 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2016 License: Apache-2.0 Imports: 10 Imported by: 0

README

item

import "github.com/coralproject/shelf/internal/sponge/item"

Overview

Index

Package files

item.go model.go

Constants

const Collection = "items"

Collection is the Mongo collection containing item values.

Variables

var ErrNotFound = errors.New("Item(s) Not found")

ErrNotFound is an error variable thrown when no results are returned from a Mongo query.

func Delete

func Delete(context interface{}, db *db.DB, id string) error

Delete removes an item from from Mongo.

func GetByIDs

func GetByIDs(context interface{}, db *db.DB, ids []string) ([]Item, error)

GetByIDs retrieves items by ID from Mongo.

func Upsert

func Upsert(context interface{}, db *db.DB, item *Item) error

Upsert upserts an item to the items collections.

type Item

type Item struct {
    ID        string                 `bson:"item_id" json:"item_id" validate:"required,min=1"`
    Type      string                 `bson:"type" json:"type" validate:"required,min=2"`
    Version   int                    `bson:"version" json:"version" validate:"required,min=1"`
    Data      map[string]interface{} `bson:"data" json:"data"`
    CreatedAt time.Time              `bson:"created_at" json:"created_at"`
    UpdatedAt time.Time              `bson:"updated_at" json:"updated_at"`
    Related   map[string]interface{} `bson:"related,omitempty" json:"related,omitempty"`
}

Item is data, properties and behavior associated with one of a comment, asset, action, etc. Regardless of type (comment, asset, etc.), all Items are formatted with an ID, Type, and Version, and asssociated data (which may differ greatly between items) is encoded into the Data interface.

func GetByID
func GetByID(context interface{}, db *db.DB, id string) (Item, error)

GetByID retrieves a single item by ID from Mongo.

func (*Item) InferIDFromData
func (item *Item) InferIDFromData() error

InferIDFromData infers an item_id from type and source id.

func (*Item) Validate
func (item *Item) Validate() error

Validate validates an Item value with the validator.


Generated by godoc2md

Documentation

Index

Constants

View Source
const Collection = "items"

Collection is the Mongo collection containing item values.

Variables

View Source
var ErrNotFound = errors.New("Item(s) Not found")

ErrNotFound is an error variable thrown when no results are returned from a Mongo query.

Functions

func Delete

func Delete(context interface{}, db *db.DB, id string) error

Delete removes an item from from Mongo.

func Upsert

func Upsert(context interface{}, db *db.DB, item *Item) error

Upsert upserts an item to the items collections.

Types

type Item

type Item struct {
	ID        string                 `bson:"item_id" json:"item_id" validate:"required,min=1"`
	Type      string                 `bson:"type" json:"type" validate:"required,min=2"`
	Version   int                    `bson:"version" json:"version" validate:"required,min=1"`
	Data      map[string]interface{} `bson:"data" json:"data"`
	CreatedAt time.Time              `bson:"created_at" json:"created_at"`
	UpdatedAt time.Time              `bson:"updated_at" json:"updated_at"`
	Related   map[string]interface{} `bson:"related,omitempty" json:"related,omitempty"`
}

Item is data, properties and behavior associated with one of a comment, asset, action, etc. Regardless of type (comment, asset, etc.), all Items are formatted with an ID, Type, and Version, and asssociated data (which may differ greatly between items) is encoded into the Data interface.

func GetByID added in v0.4.2

func GetByID(context interface{}, db *db.DB, id string) (Item, error)

GetByID retrieves a single item by ID from Mongo.

func GetByIDs

func GetByIDs(context interface{}, db *db.DB, ids []string) ([]Item, error)

GetByIDs retrieves items by ID from Mongo.

func (*Item) InferIDFromData added in v0.4.1

func (item *Item) InferIDFromData() error

InferIDFromData infers an item_id from type and source id.

func (*Item) Validate

func (item *Item) Validate() error

Validate validates an Item value with the validator.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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