driver

package
v0.1.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 19, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnsupportedType = errors.New("Unsupported type")
)

Functions

This section is empty.

Types

type Aggregate

type Aggregate interface {
	One(result interface{}, ctx ...context.Context) error
	All(result interface{}, ctx ...context.Context) error
	// SetAllowDiskUse sets the value for the AllowDiskUse field.
	SetAllowDiskUse(b bool) Aggregate

	// SetBatchSize sets the value for the BatchSize field.
	SetBatchSize(i int32) Aggregate

	// SetBypassDocumentValidation sets the value for the BypassDocumentValidation field.
	SetBypassDocumentValidation(b bool) Aggregate

	// SetCollation sets the value for the Collation field.
	SetCollation(c *options.Collation) Aggregate

	// SetMaxTime sets the value for the MaxTime field.
	SetMaxTime(d time.Duration) Aggregate

	// SetMaxAwaitTime sets the value for the MaxAwaitTime field.
	SetMaxAwaitTime(d time.Duration) Aggregate

	// SetComment sets the value for the Comment field.
	SetComment(s string) Aggregate

	// SetHint sets the value for the Hint field.
	SetHint(h interface{}) Aggregate

	Pipeline(pipeline bson.A) Aggregate

	Match(c Condition) Aggregate

	SetDatabase(db string) Aggregate

	Collection(doc interface{}) Aggregate

	SetCollReadPreference(rp *readpref.ReadPref) Aggregate

	SetCollRegistry(r *bsoncodec.Registry) Aggregate

	SetCollWriteConcern(wc *writeconcern.WriteConcern) Aggregate

	SetReadConcern(rc *readconcern.ReadConcern) Aggregate
}

type Client

type Client interface {
	// FindPagination find
	FindPagination(page, count int64, doc interface{}, ctx ...context.Context) error
	FindOneAndReplace(doc interface{}, ctx ...context.Context) error
	FindOneAndUpdate(doc interface{}, ctx ...context.Context) (*mongo.SingleResult, error)
	FindAndDelete(doc interface{}, ctx ...context.Context) error
	FindOne(doc interface{}, ctx ...context.Context) error
	FindAll(docs interface{}, ctx ...context.Context) error
	RegexFilter(key, pattern string) Session
	Distinct(doc interface{}, columns string, ctx ...context.Context) ([]interface{}, error)
	FindOneAndUpdateBson(coll interface{}, bson interface{}, ctx ...context.Context) (*mongo.SingleResult, error)

	// InsertOne insert
	InsertOne(v interface{}, ctx ...context.Context) (primitive.ObjectID, error)
	InsertMany(v interface{}, ctx ...context.Context) (*mongo.InsertManyResult, error)
	BulkWrite(docs interface{}, ctx ...context.Context) (*mongo.BulkWriteResult, error)
	ReplaceOne(doc interface{}, ctx ...context.Context) (*mongo.UpdateResult, error)

	// Update update
	Update(bean interface{}, ctx ...context.Context) (*mongo.UpdateResult, error)
	// UpdateMany The following operation updates all of the documents with quantity value less than 50.
	UpdateMany(bean interface{}, ctx ...context.Context) (*mongo.UpdateResult, error)

	UpdateOneBson(coll interface{}, bson interface{}, ctx ...context.Context) (*mongo.UpdateResult, error)

	UpdateManyBson(coll interface{}, bson interface{}, ctx ...context.Context) (*mongo.UpdateResult, error)

	// SoftDeleteOne delete
	SoftDeleteOne(filter interface{}, ctx ...context.Context) error
	SoftDeleteMany(filter interface{}, ctx ...context.Context) error
	DeleteOne(filter interface{}, ctx ...context.Context) (*mongo.DeleteResult, error)
	DeleteMany(filter interface{}, ctx ...context.Context) (*mongo.DeleteResult, error)

	// DataBase db operation
	DataBase() *mongo.Database
	// Collection(name string, db ...string) *mongo.Collection
	Collection(name string, collOpts []*options.CollectionOptions, db ...string) *mongo.Collection
	Ping() error
	Connect(ctx ...context.Context) (err error)
	Disconnect(ctx ...context.Context) error

	// Soft filter
	Soft(s bool) Session
	FilterBy(object interface{}) Session
	Filter(key string, value interface{}) Session
	Asc(colNames ...string) Session
	Eq(key string, value interface{}) Session
	Ne(key string, ne interface{}) Session
	Nin(key string, nin interface{}) Session
	Nor(c Condition) Session
	Exists(key string, exists bool, filter ...Condition) Session
	Type(key string, t interface{}) Session
	Expr(filter Condition) Session
	Regex(key string, value string) Session
	ID(id interface{}) Session
	Gt(key string, value interface{}) Session
	Gte(key string, value interface{}) Session
	Lt(key string, value interface{}) Session
	Lte(key string, value interface{}) Session
	In(key string, value interface{}) Session
	And(filter Condition) Session
	Not(key string, value interface{}) Session
	Or(filter Condition) Session
	Limit(limit int64) Session
	Skip(skip int64) Session
	Count(i interface{}, ctx ...context.Context) (int64, error)
	Desc(s1 ...string) Session
	FilterBson(d bson.D) Session
	// NewIndexes indexes
	NewIndexes() Indexes
	DropAll(doc interface{}, ctx ...context.Context) error
	DropOne(doc interface{}, name string, ctx ...context.Context) error
	AddIndex(keys interface{}, opt ...*options.IndexOptions) Indexes

	// NewSession session
	NewSession() Session
	Aggregate() Aggregate
	// CollectionNameForStruct SetDatabase(string string) Client
	CollectionNameForStruct(doc interface{}) (*schemas.Collection, error)
	CollectionNameForSlice(doc interface{}) (*schemas.Collection, error)
	Transaction(ctx context.Context, f schemas.TransFunc) error
	TransactionWithOptions(ctx context.Context, f schemas.TransFunc, opt ...*options.SessionOptions) error
}

type Condition

type Condition interface {
	RegexFilter(key, pattern string) Condition
	ID(id interface{}) Condition
	// Eq Equals a Specified Value
	//{ qty: 20 }
	//Field in Embedded Document Equals a Value
	//{"item.name": "ab" }
	// Equals an Array Value
	//{ tags: [ "A", "B" ] }
	Eq(key string, value interface{}) Condition

	// Gt {field: {$gt: value} } >
	Gt(key string, gt interface{}) Condition

	// Gte { qty: { $gte: 20 } } >=
	Gte(key string, gte interface{}) Condition

	// In { field: { $in: [<value1>, <value2>, ... <valueN> ] } }
	// tags: { $in: [ /^be/, /^st/ ] } }
	// in []string []int ...
	In(key string, in interface{}) Condition

	// Lt {field: {$lt: value} } <
	Lt(key string, lt interface{}) Condition

	// Lte { field: { $lte: value} } <=
	Lte(key string, lte interface{}) Condition

	// Ne {field: {$ne: value} } !=
	Ne(key string, ne interface{}) Condition

	// Nin { field: { $nin: [ <value1>, <value2> ... <valueN> ]} } the field does not exist.
	Nin(key string, nin interface{}) Condition

	// And { $and: [ { <expression1> }, { <expression2> } , ... , { <expressionN> } ] }
	//$and: [
	//        { $or: [ { qty: { $lt : 10 } }, { qty : { $gt: 50 } } ] },
	//        { $or: [ { sale: true }, { price : { $lt : 5 } } ] }
	// ]
	And(filter Condition) Condition

	// Not { field: { $not: { <operator-expression> } } }
	//not and Regular Expressions
	//{ item: { $not: /^p.*/ } }
	Not(key string, not interface{}) Condition

	// Nor { $nor: [ { price: 1.99 }, { price: { $exists: false } },
	// { sale: true }, { sale: { $exists: false } } ] }
	// price != 1.99 || sale != true || sale exists || sale exists
	Nor(filter Condition) Condition
	// Or { $or: [ { quantity: { $lt: 20 } }, { price: 10 } ] }
	Or(filter Condition) Condition

	Exists(key string, exists bool, filter ...Condition) Condition

	// Type { field: { $type: <BSON type> } }
	// { "_id" : 1, address : "2030 Martian Way", zipCode : "90698345" },
	// { "_id" : 2, address: "156 Lunar Place", zipCode : 43339374 },
	// db.find( { "zipCode" : { $type : 2 } } ); or db.find( { "zipCode" : { $type : "string" } }
	// return { "_id" : 1, address : "2030 Martian Way", zipCode : "90698345" }
	Type(key string, t interface{}) Condition

	// Expr Allows the use of aggregation expressions within the query language.
	//{ $expr: { <expression> } }
	//$expr can build query expressions that compare fields from the same document in a $match stage
	//todo 没用过,不知道行不行。。https://docs.mongodb.com/manual/reference/operator/query/expr/#op._S_expr
	Expr(filter Condition) Condition

	// Regex todo 简单实现,后续增加支持
	Regex(key string, value string) Condition

	Filters() (bson.D, error)
	A() bson.A
	Err() error
	FilterBson(d interface{}) Condition
	FilterBy(object interface{}) Condition

	Clone() Condition
}

type Indexes

type Indexes interface {
	CreateIndexes(doc interface{}, ctx ...context.Context) ([]string, error)

	DropAll(doc interface{}, ctx ...context.Context) error

	DropOne(doc interface{}, name string, ctx ...context.Context) error

	AddIndex(keys interface{}, opt ...*options.IndexOptions) Indexes

	// SetMaxTime sets the value for the MaxTime field.
	SetMaxTime(d time.Duration) Indexes

	// SetCommitQuorumInt sets the value for the CommitQuorum field as an int32.
	SetCommitQuorumInt(quorum int32) Indexes

	// SetCommitQuorumString sets the value for the CommitQuorum field as a string.
	SetCommitQuorumString(quorum string) Indexes

	// SetCommitQuorumMajority sets the value for the CommitQuorum to special "majority" value.
	SetCommitQuorumMajority() Indexes

	// SetCommitQuorumVotingMembers sets the value for the CommitQuorum to special "votingMembers" value.
	SetCommitQuorumVotingMembers() Indexes

	SetDatabase(db string) Indexes

	Collection(doc interface{}) Indexes
}

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

func NewParser

func NewParser(collectionMapper, columnMapper names.Mapper) *Parser

func (*Parser) Parse

func (parser *Parser) Parse(v reflect.Value) (*schemas.Collection, error)

type Session

type Session interface {
	BulkWrite(docs interface{}, ctx ...context.Context) (*mongo.BulkWriteResult, error)

	FilterBy(object interface{}) Session

	Distinct(doc interface{}, columns string, ctx ...context.Context) ([]interface{}, error)

	ReplaceOne(doc interface{}, ctx ...context.Context) (*mongo.UpdateResult, error)

	FindOneAndReplace(doc interface{}, ctx ...context.Context) error

	FindOneAndUpdate(doc interface{}, ctx ...context.Context) (*mongo.SingleResult, error)

	FindOneAndUpdateBson(coll interface{}, bson interface{}, ctx ...context.Context) (*mongo.SingleResult, error)

	FindPagination(page, count int64, doc interface{}, ctx ...context.Context) error

	FindAndDelete(doc interface{}, ctx ...context.Context) error

	// FindOne executes a find command and returns a SingleResult for one document in the collectionByName.
	FindOne(doc interface{}, ctx ...context.Context) error

	// FindAll Find executes a find command and returns a Cursor over the matching documents in the collectionByName.
	FindAll(rowsSlicePtr interface{}, ctx ...context.Context) error

	// InsertOne executes an insert command to insert a single document into the collectionByName.
	InsertOne(doc interface{}, ctx ...context.Context) (primitive.ObjectID, error)

	// InsertMany executes an insert command to insert multiple documents into the collectionByName.
	InsertMany(docs interface{}, ctx ...context.Context) (*mongo.InsertManyResult, error)

	// DeleteOne executes a delete command to delete at most one document from the collectionByName.
	DeleteOne(doc interface{}, ctx ...context.Context) (*mongo.DeleteResult, error)
	SoftDeleteOne(doc interface{}, ctx ...context.Context) error

	// DeleteMany executes a delete command to delete documents from the collectionByName.
	DeleteMany(doc interface{}, ctx ...context.Context) (*mongo.DeleteResult, error)

	SoftDeleteMany(doc interface{}, ctx ...context.Context) error

	Clone() Session
	Limit(i int64) Session

	Skip(i int64) Session

	Count(i interface{}, ctx ...context.Context) (int64, error)

	UpdateOne(bean interface{}, ctx ...context.Context) (*mongo.UpdateResult, error)

	UpdateOneBson(coll interface{}, bson interface{}, ctx ...context.Context) (*mongo.UpdateResult, error)

	UpdateManyBson(coll interface{}, bson interface{}, ctx ...context.Context) (*mongo.UpdateResult, error)

	UpdateMany(bean interface{}, ctx ...context.Context) (*mongo.UpdateResult, error)

	RegexFilter(key, pattern string) Session

	ID(id interface{}) Session

	Asc(colNames ...string) Session

	Desc(colNames ...string) Session

	Sort(colNames ...string) Session
	Soft(f bool) Session
	Filter(key string, value interface{}) Session
	FilterBson(d bson.D) Session
	// Eq Equals a Specified Value
	//{ qty: 20 }
	//Field in Embedded Document Equals a Value
	//{"item.name": "ab" }
	// Equals an Array Value
	//{ tags: [ "A", "B" ] }
	Eq(key string, value interface{}) Session

	// Gt {field: {$gt: value} } >
	Gt(key string, gt interface{}) Session

	// Gte { qty: { $gte: 20 } } >=
	Gte(key string, gte interface{}) Session

	// In { field: { $in: [<value1>, <value2>, ... <valueN> ] } }
	// tags: { $in: [ /^be/, /^st/ ] } }
	// in []string []int ...
	In(key string, in interface{}) Session

	// Lt {field: {$lt: value} } <
	Lt(key string, lt interface{}) Session

	// Lte { field: { $lte: value} } <=
	Lte(key string, lte interface{}) Session

	// Ne {field: {$ne: value} } !=
	Ne(key string, ne interface{}) Session

	// Nin { field: { $nin: [ <value1>, <value2> ... <valueN> ]} } the field does not exist.
	Nin(key string, nin interface{}) Session

	// And { $and: [ { <expression1> }, { <expression2> } , ... , { <expressionN> } ] }
	//$and: [
	//        { $or: [ { qty: { $lt : 10 } }, { qty : { $gt: 50 } } ] },
	//        { $or: [ { sale: true }, { price : { $lt : 5 } } ] }
	// ]
	And(c Condition) Session

	// Not { field: { $not: { <operator-expression> } } }
	//not and Regular Expressions
	//{ item: { $not: /^p.*/ } }
	Not(key string, not interface{}) Session

	// Nor { $nor: [ { price: 1.99 }, { price: { $exists: false } },
	// { sale: true }, { sale: { $exists: false } } ] }
	// price != 1.99 || sale != true || sale exists || sale exists
	Nor(c Condition) Session

	// Or { $or: [ { quantity: { $lt: 20 } }, { price: 10 } ] }
	Or(c Condition) Session

	Exists(key string, exists bool, filter ...Condition) Session

	// SetArrayFilters sets the value for the ArrayFilters field.
	SetArrayFilters(filters options.ArrayFilters) Session

	// SetOrdered sets the value for the Ordered field.
	SetOrdered(ordered bool) Session

	// SetBypassDocumentValidation sets the value for the BypassDocumentValidation field.
	SetBypassDocumentValidation(b bool) Session

	// SetReturnDocument sets the value for the ReturnDocument field.
	SetReturnDocument(rd options.ReturnDocument) Session

	// SetUpsert sets the value for the Upsert field.
	SetUpsert(b bool) Session

	// SetCollation sets the value for the Collation field.
	SetCollation(collation *options.Collation) Session

	// SetMaxTime sets the value for the MaxTime field.
	SetMaxTime(d time.Duration) Session

	// SetProjection sets the value for the Projection field.
	SetProjection(projection interface{}) Session

	// SetSort sets the value for the Sort field.
	SetSort(sort interface{}) Session

	// SetHint sets the value for the Hint field.
	SetHint(hint interface{}) Session

	// Type { field: { $type: <BSON type> } }
	// { "_id" : 1, address : "2030 Martian Way", zipCode : "90698345" },
	// { "_id" : 2, address: "156 Lunar Place", zipCode : 43339374 },
	// db.find( { "zipCode" : { $type : 2 } } ); or db.find( { "zipCode" : { $type : "string" } }
	// return { "_id" : 1, address : "2030 Martian Way", zipCode : "90698345" }
	Type(key string, t interface{}) Session

	// Expr Allows the use of aggregation expressions within the query language.
	//{ $expr: { <expression> } }
	//$expr can build query expressions that compare fields from the same document in a $match stage
	//todo 没用过,不知道行不行。。https://docs.mongodb.com/manual/reference/operator/query/expr/#op._S_expr
	Expr(c Condition) Session

	// Regex todo 简单实现,后续增加支持
	Regex(key string, value string) Session

	SetDatabase(db string) Session

	SetCollRegistry(r *bsoncodec.Registry) Session

	SetCollReadPreference(rp *readpref.ReadPref) Session

	SetCollWriteConcern(wc *writeconcern.WriteConcern) Session

	SetReadConcern(rc *readconcern.ReadConcern) Session
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL