mirror of
https://github.com/mainnika/mongox-go-driver.git
synced 2026-05-23 00:03:36 +00:00
Add mongo client interfaces
This commit is contained in:
@@ -14,7 +14,7 @@ import (
|
||||
"github.com/mainnika/mongox-go-driver/mongox/query"
|
||||
)
|
||||
|
||||
func createSimpleLoad(db *mongox.Database, target interface{}, composed *query.Query) (cursor *mongo.Cursor, err error) {
|
||||
func createSimpleLoad(db mongox.Database, target interface{}, composed *query.Query) (cursor *mongo.Cursor, err error) {
|
||||
|
||||
collection := db.GetCollectionOf(target)
|
||||
opts := options.Find()
|
||||
@@ -26,7 +26,7 @@ func createSimpleLoad(db *mongox.Database, target interface{}, composed *query.Q
|
||||
return collection.Find(db.Context(), composed.M(), opts)
|
||||
}
|
||||
|
||||
func createAggregateLoad(db *mongox.Database, target interface{}, composed *query.Query) (cursor *mongo.Cursor, err error) {
|
||||
func createAggregateLoad(db mongox.Database, target interface{}, composed *query.Query) (cursor *mongo.Cursor, err error) {
|
||||
|
||||
collection := db.GetCollectionOf(target)
|
||||
opts := options.Aggregate()
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
|
||||
// Count function counts documents in the database by query
|
||||
// target is used only to get collection by tag so it'd be better to use nil ptr here
|
||||
func Count(db *mongox.Database, target interface{}, filters ...interface{}) (int64, error) {
|
||||
func Count(db mongox.Database, target interface{}, filters ...interface{}) (int64, error) {
|
||||
|
||||
collection := db.GetCollectionOf(target)
|
||||
opts := options.Count()
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
// DeleteArray removes documents list from a database by their ids
|
||||
func DeleteArray(db *mongox.Database, target interface{}) error {
|
||||
func DeleteArray(db mongox.Database, target interface{}) error {
|
||||
|
||||
targetV := reflect.ValueOf(target)
|
||||
targetT := targetV.Type()
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
)
|
||||
|
||||
// DeleteOne removes a document from a database and then returns it into target
|
||||
func DeleteOne(db *mongox.Database, target interface{}, filters ...interface{}) error {
|
||||
func DeleteOne(db mongox.Database, target interface{}, filters ...interface{}) error {
|
||||
|
||||
collection := db.GetCollectionOf(target)
|
||||
opts := &options.FindOneAndDeleteOptions{}
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
// LoadArray loads an array of documents from the database by query
|
||||
func LoadArray(db *mongox.Database, target interface{}, filters ...interface{}) error {
|
||||
func LoadArray(db mongox.Database, target interface{}, filters ...interface{}) error {
|
||||
|
||||
targetV := reflect.ValueOf(target)
|
||||
targetT := targetV.Type()
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
// LoadOne function loads a first single target document by a query
|
||||
func LoadOne(db *mongox.Database, target interface{}, filters ...interface{}) error {
|
||||
func LoadOne(db mongox.Database, target interface{}, filters ...interface{}) error {
|
||||
|
||||
composed := query.Compose(append(filters, query.Limit(1))...)
|
||||
hasPreloader, _ := composed.Preloader()
|
||||
|
||||
@@ -55,7 +55,7 @@ func (l *StreamLoader) Close() error {
|
||||
}
|
||||
|
||||
// LoadStream function loads documents one by one into a target channel
|
||||
func LoadStream(db *mongox.Database, target interface{}, filters ...interface{}) (*StreamLoader, error) {
|
||||
func LoadStream(db mongox.Database, target interface{}, filters ...interface{}) (*StreamLoader, error) {
|
||||
|
||||
var cursor *mongo.Cursor
|
||||
var err error
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
)
|
||||
|
||||
// SaveOne saves a single source document to the database
|
||||
func SaveOne(db *mongox.Database, source interface{}) error {
|
||||
func SaveOne(db mongox.Database, source interface{}) error {
|
||||
|
||||
collection := db.GetCollectionOf(source)
|
||||
opts := options.FindOneAndReplace()
|
||||
|
||||
Reference in New Issue
Block a user