mgocrud/types.go
2022-02-09 21:57:31 +01:00

72 lines
1.7 KiB
Go

package mgocrud
import (
"errors"
"gopkg.in/mgo.v2/bson"
)
var (
ErrNotFound = errors.New("not found")
)
type Connection interface {
Close()
NewSession() Session
}
type Session interface {
Close()
DB(name string) Database
}
type Database interface {
Session() Session
C(name string) Collection
Name() string
EnsureIndex(m ModelInterface) error
ValidateObject(m ModelInterface, changes bson.M) error
ReadDocument(m ModelInterface, selector bson.M) error
CreateDocument(m ModelInterface) error
ReadCollection(results interface{}, filter bson.M, selector bson.M, offset int, limit int, sort []string, pipelineModifier PipelineModifierFunction) error
ReadCollectionCount(m ModelInterface, filter bson.M) (count int, err error)
UpdateDocument(m ModelInterface, changes bson.M) error
UpsertDocument(m ModelInterface, changes bson.M) error
DeleteDocument(m ModelInterface) error
DeleteDocuments(m ModelInterface, filter bson.M) (removed int, err error)
}
type Collection interface {
Insert(docs ...interface{}) error
UpdateId(id interface{}, update interface{}) error
RemoveId(id interface{}) error
Upsert(selector interface{}, update interface{}) (ChangeInfo, error)
RemoveAll(filter interface{}) (ChangeInfo, error)
FindId(id interface{}) Query
Find(query interface{}) Query
EnsureIndex(index Index) error
Pipe(pipeline interface{}) Pipe
}
type ChangeInfo interface {
Matched() int
Removed() int
Updated() int
}
type Query interface {
Select(selector interface{}) Query
One(result interface{}) error
Sort(fields ...string) Query
Skip(n int) Query
Limit(n int) Query
All(result interface{}) error
Count() (int, error)
}
type Index interface{}
type Pipe interface {
All(result interface{}) error
}