Remove unused interfaces

v2
Nikita Tokarchuk 4 years ago
parent 06b1ef5d9a
commit f1fe41d336
  1. 8
      mongox/base/reset.go
  2. 4
      mongox/database/database.go
  3. 68
      mongox/mongox.go

@ -2,14 +2,16 @@ package base
import (
"reflect"
"github.com/mainnika/mongox-go-driver/v2/mongox"
)
// Reset function creates new zero object for the target pointer
func Reset(target interface{}) {
resettable, canReset := target.(mongox.Resetter)
type resetter interface {
Reset()
}
resettable, canReset := target.(resetter)
if canReset {
resettable.Reset()
return

@ -33,7 +33,7 @@ func NewDatabase(client *mongo.Client, dbname string) mongox.Database {
}
// Client function returns a mongo client
func (d *Database) Client() mongox.MongoClient {
func (d *Database) Client() *mongo.Client {
return d.client
}
@ -67,7 +67,7 @@ func (d *Database) New(ctx context.Context) mongox.Database {
// base.ObjectID `bson:",inline" json:",inline" collection:"foobars"`
// ...
// Will panic if there is no «collection» tag
func (d *Database) GetCollectionOf(document interface{}) mongox.MongoCollection {
func (d *Database) GetCollectionOf(document interface{}) *mongo.Collection {
el := reflect.TypeOf(document).Elem()
numField := el.NumField()

@ -5,17 +5,15 @@ import (
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"go.mongodb.org/mongo-driver/mongo/readpref"
)
// Database is the mongox database interface
type Database interface {
Client() MongoClient
Client() *mongo.Client
Context() context.Context
Name() string
New(ctx context.Context) Database
GetCollectionOf(document interface{}) MongoCollection
GetCollectionOf(document interface{}) *mongo.Collection
Count(target interface{}, filters ...interface{}) (int64, error)
DeleteArray(target interface{}) error
DeleteOne(target interface{}, filters ...interface{}) error
@ -34,68 +32,6 @@ type StreamLoader interface {
Err() error
}
// MongoClient is the mongo client interface
type MongoClient interface {
Connect(ctx context.Context) error
Disconnect(ctx context.Context) error
Ping(ctx context.Context, rp *readpref.ReadPref) error
StartSession(opts ...*options.SessionOptions) (mongo.Session, error)
Database(name string, opts ...*options.DatabaseOptions) *mongo.Database
ListDatabases(ctx context.Context, filter interface{}, opts ...*options.ListDatabasesOptions) (mongo.ListDatabasesResult, error)
ListDatabaseNames(ctx context.Context, filter interface{}, opts ...*options.ListDatabasesOptions) ([]string, error)
UseSession(ctx context.Context, fn func(mongo.SessionContext) error) error
UseSessionWithOptions(ctx context.Context, opts *options.SessionOptions, fn func(mongo.SessionContext) error) error
Watch(ctx context.Context, pipeline interface{}, opts ...*options.ChangeStreamOptions) (*mongo.ChangeStream, error)
NumberSessionsInProgress() int
}
// MongoCollection is the mongo collection interface
type MongoCollection interface {
Clone(opts ...*options.CollectionOptions) (*mongo.Collection, error)
Name() string
Database() *mongo.Database
BulkWrite(ctx context.Context, models []mongo.WriteModel, opts ...*options.BulkWriteOptions) (*mongo.BulkWriteResult, error)
InsertOne(ctx context.Context, document interface{}, opts ...*options.InsertOneOptions) (*mongo.InsertOneResult, error)
InsertMany(ctx context.Context, documents []interface{}, opts ...*options.InsertManyOptions) (*mongo.InsertManyResult, error)
DeleteOne(ctx context.Context, filter interface{}, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)
DeleteMany(ctx context.Context, filter interface{}, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)
UpdateOne(ctx context.Context, filter interface{}, update interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)
UpdateMany(ctx context.Context, filter interface{}, update interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)
ReplaceOne(ctx context.Context, filter interface{}, replacement interface{}, opts ...*options.ReplaceOptions) (*mongo.UpdateResult, error)
Aggregate(ctx context.Context, pipeline interface{}, opts ...*options.AggregateOptions) (*mongo.Cursor, error)
CountDocuments(ctx context.Context, filter interface{}, opts ...*options.CountOptions) (int64, error)
EstimatedDocumentCount(ctx context.Context, opts ...*options.EstimatedDocumentCountOptions) (int64, error)
Distinct(ctx context.Context, fieldName string, filter interface{}, opts ...*options.DistinctOptions) ([]interface{}, error)
Find(ctx context.Context, filter interface{}, opts ...*options.FindOptions) (*mongo.Cursor, error)
FindOne(ctx context.Context, filter interface{}, opts ...*options.FindOneOptions) *mongo.SingleResult
FindOneAndDelete(ctx context.Context, filter interface{}, opts ...*options.FindOneAndDeleteOptions) *mongo.SingleResult
FindOneAndReplace(ctx context.Context, filter interface{}, replacement interface{}, opts ...*options.FindOneAndReplaceOptions) *mongo.SingleResult
FindOneAndUpdate(ctx context.Context, filter interface{}, update interface{}, opts ...*options.FindOneAndUpdateOptions) *mongo.SingleResult
Watch(ctx context.Context, pipeline interface{}, opts ...*options.ChangeStreamOptions) (*mongo.ChangeStream, error)
Indexes() mongo.IndexView
Drop(ctx context.Context) error
}
// Saver is an interface for documents that can be saved
type Saver interface {
Save(db Database) error
}
// Deleter is an interface for documents that can be deleted
type Deleter interface {
Delete(db Database) error
}
// Loader is an interface for documents that can be loaded
type Loader interface {
Load(db Database, filters ...interface{}) error
}
// Resetter is an interface for documenta that can be resetted
type Resetter interface {
Reset()
}
// OIDBased is an interface for documents that have objectId type for the _id field
type OIDBased interface {
GetID() primitive.ObjectID

Loading…
Cancel
Save