Documentation ¶
Index ¶
- Constants
- func CascadeDelete(collection *Collection, doc interface{})
- func CascadeSave(collection *Collection, doc Document) error
- func GetBsonName(field reflect.StructField) string
- func GetChangedFields(struct1 interface{}, struct2 interface{}, useBson bool) ([]string, error)
- func MapFromCascadeProperties(properties []string, doc Document) map[string]interface{}
- func ValidateInclusionIn(value string, options []string) bool
- func ValidateMongoIdRef(id bson.ObjectId, collection *Collection) bool
- func ValidateRequired(val interface{}) bool
- type AfterDeleteHook
- type AfterFindHook
- type AfterSaveHook
- type BeforeDeleteHook
- type BeforeSaveHook
- type CascadeConfig
- type CascadeFilter
- type CascadingDocument
- type Collection
- func (c *Collection) Collection() *mgo.Collection
- func (c *Collection) Delete(query bson.M) (*mgo.ChangeInfo, error)
- func (c *Collection) DeleteDocument(doc Document) error
- func (c *Collection) DeleteOne(query bson.M) error
- func (c *Collection) Find(query interface{}) *ResultSet
- func (c *Collection) FindById(id bson.ObjectId, doc interface{}) error
- func (c *Collection) FindOne(query interface{}, doc interface{}) error
- func (c *Collection) PreSave(doc Document) error
- func (c *Collection) Save(doc Document) error
- type Config
- type Connection
- type DiffTracker
- func (d *DiffTracker) Clear()
- func (d *DiffTracker) Compare(useBson bool) (bool, []string, error)
- func (d *DiffTracker) GetModified(useBson bool) (bool, []string)
- func (d *DiffTracker) GetOriginalValue(field string) (interface{}, error)
- func (d *DiffTracker) Modified(field string) bool
- func (d *DiffTracker) NewSession(useBsonTags bool) (*DiffTrackingSession, error)
- func (d *DiffTracker) Reset()
- func (d *DiffTracker) SetOriginal(orig interface{})
- type DiffTrackingSession
- type Document
- type DocumentBase
- type DocumentNotFoundError
- type NewTracker
- type PaginationInfo
- type ReferenceField
- type ResultSet
- type Stringer
- type TimeTracker
- type Trackable
- type ValidateHook
- type ValidationError
Constants ¶
const ( REL_MANY = iota REL_ONE = iota )
Relation types (one-to-many or one-to-one)
Variables ¶
This section is empty.
Functions ¶
func CascadeDelete ¶
func CascadeDelete(collection *Collection, doc interface{})
Deletes references to a document from its related documents
func CascadeSave ¶
func CascadeSave(collection *Collection, doc Document) error
Cascades a document's properties to related documents, after it has been prepared for db insertion (encrypted, etc)
func GetBsonName ¶
func GetBsonName(field reflect.StructField) string
func GetChangedFields ¶ added in v0.10.0
func MapFromCascadeProperties ¶
If you need to, you can use this to construct the data map that will be cascaded down to related documents. Doing this is not recommended unless the cascaded fields are dynamic.
func ValidateInclusionIn ¶
func ValidateMongoIdRef ¶
func ValidateMongoIdRef(id bson.ObjectId, collection *Collection) bool
func ValidateRequired ¶
func ValidateRequired(val interface{}) bool
Types ¶
type AfterDeleteHook ¶
type AfterDeleteHook interface {
AfterDelete(*Collection) error
}
type AfterFindHook ¶
type AfterFindHook interface {
AfterFind(*Collection) error
}
type AfterSaveHook ¶
type AfterSaveHook interface {
AfterSave(*Collection) error
}
type BeforeDeleteHook ¶
type BeforeDeleteHook interface {
BeforeDelete(*Collection) error
}
type BeforeSaveHook ¶
type BeforeSaveHook interface {
BeforeSave(*Collection) error
}
type CascadeConfig ¶
type CascadeConfig struct { // The collection to cascade to Collection *Collection // The relation type (does the target doc have an array of these docs [REL_MANY] or just reference a single doc [REL_ONE]) RelType int // The property on the related doc to populate ThroughProp string // The query to find related docs Query bson.M // The data that constructs the query may have changed - this is to remove self from previous relations OldQuery bson.M // Should it also cascade the related doc on save? Nest bool // If there is no through prop, we need to know which properties to nullify if a document is deleted // and cascades to the root level of a related document. These are also used to nullify the previous relation // if the relation ID is changed Properties []string // Full data to cascade down to the related document. Note Data interface{} // An instance of the related doc if it needs to be nested Instance Document // If this is true, then just run the "remove" parts of the queries, instead of the remove + add RemoveOnly bool // If this is provided, use this field instead of _id for determining "sameness". This must also be a bson.ObjectId field ReferenceQuery []*ReferenceField }
Configuration to tell Bongo how to cascade data to related documents on save or delete
type CascadeFilter ¶
type CascadeFilter func(data map[string]interface{})
type CascadingDocument ¶
type CascadingDocument interface {
GetCascade(*Collection) []*CascadeConfig
}
type Collection ¶
type Collection struct { Name string Connection *Connection }
func (*Collection) Collection ¶
func (c *Collection) Collection() *mgo.Collection
func (*Collection) Delete ¶
func (c *Collection) Delete(query bson.M) (*mgo.ChangeInfo, error)
Convenience method which just delegates to mgo. Note that hooks are NOT run
func (*Collection) DeleteDocument ¶ added in v0.9.4
func (c *Collection) DeleteDocument(doc Document) error
func (*Collection) DeleteOne ¶ added in v0.9.4
func (c *Collection) DeleteOne(query bson.M) error
Convenience method which just delegates to mgo. Note that hooks are NOT run
func (*Collection) Find ¶
func (c *Collection) Find(query interface{}) *ResultSet
This doesn't actually do any DB interaction, it just creates the result set so we can start looping through on the iterator
func (*Collection) FindById ¶
func (c *Collection) FindById(id bson.ObjectId, doc interface{}) error
func (*Collection) FindOne ¶
func (c *Collection) FindOne(query interface{}, doc interface{}) error
func (*Collection) PreSave ¶ added in v0.9.5
func (c *Collection) PreSave(doc Document) error
func (*Collection) Save ¶
func (c *Collection) Save(doc Document) error
type Connection ¶
type Connection struct { Config *Config Session *mgo.Session }
func Connect ¶
func Connect(config *Config) (*Connection, error)
Create a new connection and run Connect()
func (*Connection) Collection ¶
func (m *Connection) Collection(name string) *Collection
func (*Connection) Connect ¶
func (m *Connection) Connect() (err error)
Connect to the database using the provided config
type DiffTracker ¶
type DiffTracker struct {
// contains filtered or unexported fields
}
func NewDiffTracker ¶
func NewDiffTracker(doc interface{}) *DiffTracker
func (*DiffTracker) Clear ¶
func (d *DiffTracker) Clear()
func (*DiffTracker) GetModified ¶
func (d *DiffTracker) GetModified(useBson bool) (bool, []string)
func (*DiffTracker) GetOriginalValue ¶
func (d *DiffTracker) GetOriginalValue(field string) (interface{}, error)
func (*DiffTracker) Modified ¶
func (d *DiffTracker) Modified(field string) bool
func (*DiffTracker) NewSession ¶
func (d *DiffTracker) NewSession(useBsonTags bool) (*DiffTrackingSession, error)
func (*DiffTracker) Reset ¶
func (d *DiffTracker) Reset()
func (*DiffTracker) SetOriginal ¶ added in v0.10.1
func (d *DiffTracker) SetOriginal(orig interface{})
type DiffTrackingSession ¶
func (*DiffTrackingSession) Modified ¶
func (s *DiffTrackingSession) Modified(field string) bool
type DocumentBase ¶
type DocumentBase struct { Id bson.ObjectId `bson:"_id,omitempty" json:"_id"` Created time.Time `bson:"_created" json:"_created"` Modified time.Time `bson:"_modified" json:"_modified"` // contains filtered or unexported fields }
func (*DocumentBase) GetId ¶
func (d *DocumentBase) GetId() bson.ObjectId
Satisfy the document interface
func (*DocumentBase) IsNew ¶
func (d *DocumentBase) IsNew() bool
func (*DocumentBase) SetCreated ¶
func (d *DocumentBase) SetCreated(t time.Time)
func (*DocumentBase) SetId ¶
func (d *DocumentBase) SetId(id bson.ObjectId)
func (*DocumentBase) SetIsNew ¶
func (d *DocumentBase) SetIsNew(isNew bool)
Satisfy the new tracker interface
func (*DocumentBase) SetModified ¶
func (d *DocumentBase) SetModified(t time.Time)
type DocumentNotFoundError ¶
type DocumentNotFoundError struct{}
func (DocumentNotFoundError) Error ¶
func (d DocumentNotFoundError) Error() string
type NewTracker ¶
type PaginationInfo ¶
type ReferenceField ¶
type ReferenceField struct { BsonName string Value interface{} }
type ResultSet ¶
type ResultSet struct { Query *mgo.Query Iter *mgo.Iter Collection *Collection Error error Params interface{} // contains filtered or unexported fields }
type Trackable ¶
type Trackable interface {
GetDiffTracker() *DiffTracker
}
type ValidateHook ¶
type ValidateHook interface {
Validate(*Collection) []error
}
type ValidationError ¶
type ValidationError struct {
Errors []error
}
func (*ValidationError) Error ¶
func (v *ValidationError) Error() string