Documentation
¶
Overview ¶
Package coal provides a mini ORM for mongoDB.
Index ¶
- func A(m Model, field string) string
- func C(m Model) string
- func Contains(list []bson.ObjectId, id bson.ObjectId) bool
- func F(m Model, field string) string
- func Includes(all, subset []bson.ObjectId) bool
- func N() *bson.ObjectId
- func P(id bson.ObjectId) *bson.ObjectId
- func R(m Model, field string) string
- func T(t time.Time) *time.Time
- func Unique(ids []bson.ObjectId) []bson.ObjectId
- type Base
- type Catalog
- type Event
- type Field
- type HasMany
- type HasOne
- type Indexer
- type Meta
- type Model
- type Receiver
- type Store
- type Stream
- type SubStore
- type Tester
- func (t *Tester) Clean()
- func (t *Tester) Delete(model Model)
- func (t *Tester) Fetch(model Model, id bson.ObjectId) Model
- func (t *Tester) FindAll(model Model) interface{}
- func (t *Tester) FindLast(model Model) Model
- func (t *Tester) Save(model Model) Model
- func (t *Tester) Update(model Model) Model
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func A ¶
A is a short-hand function to extract the attribute JSON key of a model field.
Note: A will panic if no field has been found.
func Contains ¶ added in v0.15.0
Contains returns true if a list of object ids contains the specified id.
func F ¶
F is a short-hand function to extract the database BSON field name of a model field. Additionally, it supports the "-" prefix for retrieving sort keys.
Note: F will panic if no field has been found.
func Includes ¶ added in v0.15.1
Includes returns true if a list of object ids includes another list of object ids.
func R ¶ added in v0.11.2
R is a short-hand function to extract the relationship name of a model field.
Note: R will panic if no field has been found.
Types ¶
type Base ¶
type Base struct { DocID bson.ObjectId `json:"-" bson:"_id"` // contains filtered or unexported fields }
Base is the base for every coal model.
type Catalog ¶ added in v0.8.8
type Catalog struct {
// contains filtered or unexported fields
}
A Catalog provides a mechanism for models to access each others meta data.
func NewCatalog ¶ added in v0.8.8
NewCatalog will create a new catalog.
type Field ¶
type Field struct { // The struct field name e.g. "TireSize". Name string // The struct field type and kind. Type reflect.Type Kind reflect.Kind // The JSON object key name e.g. "tire-size". JSONKey string // The BSON document field e.g. "tire_size". BSONField string // Whether the field is a pointer and thus optional. Optional bool // The relationship status. ToOne bool ToMany bool HasOne bool HasMany bool // The relationship information. RelName string RelType string RelInverse string // contains filtered or unexported fields }
A Field contains the meta information about a single field of a model.
type HasMany ¶
type HasMany struct{}
The HasMany type denotes a has-many relationship in a model declaration.
type HasOne ¶ added in v0.8.3
type HasOne struct{}
The HasOne type denotes a has-one relationship in a model declaration.
Has-one relationships requires that the referencing side is ensuring that the reference is unique. In fire this should be done using a uniqueness validator and a unique index on the collection.
type Indexer ¶
type Indexer struct {
// contains filtered or unexported fields
}
An Indexer can be used to manage indexes for models.
func (*Indexer) Add ¶
Add will add an index to the internal index list. Fields that are prefixed with a dash will result in an descending index. See the MongoDB documentation for more details.
func (*Indexer) AddPartial ¶ added in v0.17.1
func (i *Indexer) AddPartial(model Model, unique bool, expireAfter time.Duration, fields []string, filter bson.M)
AddPartial is similar to Add except that it adds a partial index.
type Meta ¶
type Meta struct { // The struct type name e.g. "models.CarWheel". Name string // The plural resource name e.g. "car-wheels". PluralName string // The collection name e.g. "car_wheels". Collection string // The struct fields. Fields map[string]*Field // The struct fields ordered. OrderedFields []*Field // The database fields. DatabaseFields map[string]*Field // The attributes. Attributes map[string]*Field // The relationships. Relationships map[string]*Field // contains filtered or unexported fields }
Meta stores extracted meta data from a model.
func NewMeta ¶
NewMeta returns the Meta structure for the passed Model.
Note: This method panics if the passed Model has invalid fields and tags.
type Model ¶
type Model interface { ID() bson.ObjectId Meta() *Meta MustGet(string) interface{} MustSet(string, interface{}) // contains filtered or unexported methods }
Model is the main interface implemented by every coal model embedding Base.
type Store ¶
A Store manages the usage of database connections.
func CreateStore ¶
CreateStore will dial the passed database and return a new store. It will return an error if the initial connection failed
func MustCreateStore ¶
MustCreateStore will dial the passed database and return a new store. It will panic if the initial connection failed.
type Stream ¶ added in v0.17.1
type Stream struct { // Reporter is called with errors. Reporter func(error) // contains filtered or unexported fields }
Stream simplifies the handling of change streams to receives changes to documents.
type SubStore ¶
A SubStore allows access to the database.
func (*SubStore) C ¶
func (s *SubStore) C(model Model) *mgo.Collection
C will return the collection associated to the passed model.
type Tester ¶ added in v0.17.1
type Tester struct { // The store to use for cleaning the database. Store *Store // The registered models. Models []Model }
A Tester provides facilities to the test a fire API.
func (*Tester) Clean ¶ added in v0.17.1
func (t *Tester) Clean()
Clean will remove the collections of models that have been registered and reset the header map.