Files
mgoapi/dbinterface.go
2022-02-09 20:33:13 +01:00

63 lines
1.7 KiB
Go

package mgoapi
import (
"gitbase.de/gopackage/mgocrud/v2"
"gopkg.in/mgo.v2/bson"
)
type Session interface {
Close()
Copy() Session
DB(name string) Database
}
type Database interface {
Session() Session
C(name string) Collection
Name() string
EnsureIndex(m mgocrud.ModelInterface) error
ValidateObject(m mgocrud.ModelInterface, changes bson.M) error
ReadDocument(m mgocrud.ModelInterface, selector bson.M) error
CreateDocument(m mgocrud.ModelInterface) error
ReadCollection(results interface{}, filter bson.M, selector bson.M, offset int, limit int, sort []string, pipelineModifier mgocrud.PipelineModifierFunction) error
ReadCollectionCount(m mgocrud.ModelInterface, filter bson.M) (count int, err error)
UpdateDocument(m mgocrud.ModelInterface, changes bson.M) error
UpsertDocument(m mgocrud.ModelInterface, changes bson.M) error
DeleteDocument(m mgocrud.ModelInterface) error
DeleteDocuments(m mgocrud.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
}