Documentation
¶
Overview ¶
Package model implements a basic model abstraction for structs.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Base ¶
type Base struct {
DocID bson.ObjectId `json:"-" bson:"_id,omitempty"`
// contains filtered or unexported fields
}
Base is the base for every fire model.
func (*Base) MustGet ¶
MustGet returns the value of the given field.
Note: MustGet will return the value of the first field that has a matching Name, JSONName, or BSONName and will panic if no field can be found.
func (*Base) MustSet ¶
MustSet will set the given field to the the passed valued.
Note: MustSet will set the value of the first field that has a matching Name, JSONName, or BSONName and will panic if no field can been found. The method will also panic if the type of the field and the passed value do not match.
type Field ¶
type Field struct {
Name string
Type reflect.Type
Kind reflect.Kind
JSONName string
BSONName string
Optional bool
ToOne bool
ToMany bool
HasMany bool
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 Meta ¶
type Meta struct {
Name string
PluralName string
Collection string
Fields []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.
func (*Meta) FindField ¶
FindField returns the first field that has a matching Name, JSONName, or BSONName. FindField will return nil if no field has been found.
func (*Meta) Make ¶
Make returns a pointer to a new zero initialized model e.g. *Post.
Note: Other libraries like mgo might replace the pointer content with a new structure, therefore the model eventually needs to be initialized again using Init().
func (*Meta) MakeSlice ¶
func (m *Meta) MakeSlice() interface{}
MakeSlice returns a pointer to a zero length slice of the model e.g. *[]*Post.
Note: Don't forget to initialize the slice using InitSlice() after adding elements with libraries like mgo.
func (*Meta) MustFindField ¶
MustFindField returns the first field that has a matching Name, JSONName, or BSONName. MustFindField will panic if no field has been found.
type Model ¶
type Model interface {
ID() bson.ObjectId
MustGet(string) interface{}
MustSet(string, interface{})
Meta() *Meta
// contains filtered or unexported methods
}
Model is the main interface implemented by every fire model embedding Base.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
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.
func (*Store) C ¶
func (s *Store) C(model Model) *mgo.Collection
C will return the collection associated to the passed model.
func (*Store) Close ¶
func (s *Store) Close()
Close will close the store and its associated session.