Organize backend into product executable and shared Go modules
This commit is contained in:
1 parent
981e84a4b4
commit
f0720ec66b
382 files changed
+1944
-6989
No files matched your search
@@ -0,0 +1,11 @@
|
||||
package builder
|
||||
|
||||
import "go.mongodb.org/mongo-driver/v2/bson"
|
||||
|
||||
type Accumulator interface {
|
||||
Build() bson.D
|
||||
}
|
||||
|
||||
type GroupAccumulator interface {
|
||||
Build() bson.D
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package builder
|
||||
|
||||
import "go.mongodb.org/mongo-driver/v2/bson"
|
||||
|
||||
type Alias interface {
|
||||
Field() Field
|
||||
Build() bson.D
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package builder
|
||||
|
||||
import "go.mongodb.org/mongo-driver/v2/bson"
|
||||
|
||||
type Array interface {
|
||||
Build() bson.A
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package builder
|
||||
|
||||
type Expression interface {
|
||||
Build() any
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package builder
|
||||
|
||||
type Field interface {
|
||||
Dot(field string) Field
|
||||
CopyWith(field string) Field
|
||||
Build() string
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package builder
|
||||
|
||||
type MongoKeyword string
|
||||
|
||||
const (
|
||||
MKAs MongoKeyword = "as"
|
||||
MKForeignField MongoKeyword = "foreignField"
|
||||
MKFrom MongoKeyword = "from"
|
||||
MKIncludeArrayIndex MongoKeyword = "includeArrayIndex"
|
||||
MKLet MongoKeyword = "let"
|
||||
MKLocalField MongoKeyword = "localField"
|
||||
MKPath MongoKeyword = "path"
|
||||
MKPipeline MongoKeyword = "pipeline"
|
||||
MKPreserveNullAndEmptyArrays MongoKeyword = "preserveNullAndEmptyArrays"
|
||||
MKNewRoot MongoKeyword = "newRoot"
|
||||
)
|
||||
@@ -0,0 +1,57 @@
|
||||
package builder
|
||||
|
||||
type MongoOperation string
|
||||
|
||||
const (
|
||||
// Comparison operators
|
||||
Gt MongoOperation = "$gt"
|
||||
Lt MongoOperation = "$lt"
|
||||
Gte MongoOperation = "$gte"
|
||||
Lte MongoOperation = "$lte"
|
||||
Eq MongoOperation = "$eq"
|
||||
Ne MongoOperation = "$ne"
|
||||
In MongoOperation = "$in"
|
||||
NotIn MongoOperation = "$nin"
|
||||
Exists MongoOperation = "$exists"
|
||||
|
||||
// Logical operators
|
||||
And MongoOperation = "$and"
|
||||
Or MongoOperation = "$or"
|
||||
Not MongoOperation = "$not"
|
||||
|
||||
AddToSet MongoOperation = "$addToSet"
|
||||
Avg MongoOperation = "$avg"
|
||||
Pull MongoOperation = "$pull"
|
||||
Count MongoOperation = "$count"
|
||||
Cond MongoOperation = "$cond"
|
||||
Each MongoOperation = "$each"
|
||||
Expr MongoOperation = "$expr"
|
||||
First MongoOperation = "$first"
|
||||
Group MongoOperation = "$group"
|
||||
IfNull MongoOperation = "$ifNull"
|
||||
Limit MongoOperation = "$limit"
|
||||
Literal MongoOperation = "$literal"
|
||||
Lookup MongoOperation = "$lookup"
|
||||
Match MongoOperation = "$match"
|
||||
Max MongoOperation = "$max"
|
||||
Min MongoOperation = "$min"
|
||||
Push MongoOperation = "$push"
|
||||
Project MongoOperation = "$project"
|
||||
Set MongoOperation = "$set"
|
||||
Inc MongoOperation = "$inc"
|
||||
Unset MongoOperation = "$unset"
|
||||
Rename MongoOperation = "$rename"
|
||||
ReplaceRoot MongoOperation = "$replaceRoot"
|
||||
SetUnion MongoOperation = "$setUnion"
|
||||
Size MongoOperation = "$size"
|
||||
Sort MongoOperation = "$sort"
|
||||
Skip MongoOperation = "$skip"
|
||||
Sum MongoOperation = "$sum"
|
||||
Type MongoOperation = "$type"
|
||||
Unwind MongoOperation = "$unwind"
|
||||
|
||||
Add MongoOperation = "$add"
|
||||
Subtract MongoOperation = "$subtract"
|
||||
Multiply MongoOperation = "$multiply"
|
||||
Divide MongoOperation = "$divide"
|
||||
)
|
||||
@@ -0,0 +1,16 @@
|
||||
package builder
|
||||
|
||||
import "go.mongodb.org/mongo-driver/v2/bson"
|
||||
|
||||
// Patch defines operations for constructing partial update documents.
|
||||
// Each builder method returns the same Patch instance to allow chaining.
|
||||
type Patch interface {
|
||||
Set(field Field, value any) Patch
|
||||
Inc(field Field, value any) Patch
|
||||
Unset(field Field) Patch
|
||||
Rename(field Field, newName string) Patch
|
||||
Push(field Field, value any) Patch
|
||||
Pull(field Field, value any) Patch
|
||||
AddToSet(field Field, value any) Patch
|
||||
Build() bson.D
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package builder
|
||||
|
||||
import (
|
||||
"git.sendico.io/tech/sxchnge/shared/service"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
)
|
||||
|
||||
type Pipeline interface {
|
||||
Match(filter Query) Pipeline
|
||||
Lookup(from mservice.Type, localField, foreignField, as Field) Pipeline
|
||||
LookupWithPipeline(
|
||||
from mservice.Type,
|
||||
pipeline Pipeline, // your nested pipeline
|
||||
as Field,
|
||||
let *map[string]Field, // optional e.g. {"projRef": Field("$_id")}
|
||||
) Pipeline
|
||||
// unwind with functional options
|
||||
Unwind(path Field, opts ...UnwindOption) Pipeline
|
||||
Count(field Field) Pipeline
|
||||
Group(groupBy Alias, accumulators ...GroupAccumulator) Pipeline
|
||||
Project(projections ...Projection) Pipeline
|
||||
ReplaceRoot(newRoot Expression) Pipeline
|
||||
Build() mongo.Pipeline
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package builder
|
||||
|
||||
import "go.mongodb.org/mongo-driver/v2/bson"
|
||||
|
||||
type Projection interface {
|
||||
Build() bson.D
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package builder
|
||||
|
||||
import (
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo/options"
|
||||
)
|
||||
|
||||
type Query interface {
|
||||
Filter(field Field, value any) Query
|
||||
And(filters ...Query) Query
|
||||
Or(filters ...Query) Query
|
||||
Expression(value Expression) Query
|
||||
Comparison(field Field, operator MongoOperation, value any) Query
|
||||
RegEx(field Field, pattern, options string) Query
|
||||
In(field Field, values ...any) Query
|
||||
NotIn(field Field, values ...any) Query
|
||||
Sort(field Field, ascending bool) Query
|
||||
Limit(limit *int64) Query
|
||||
Offset(offset *int64) Query
|
||||
Archived(isArchived *bool) Query
|
||||
BuildPipeline() bson.D
|
||||
BuildQuery() bson.D
|
||||
BuildOptions() *options.FindOptionsBuilder
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package builder
|
||||
|
||||
// UnwindOption is a functional option for configuring the $unwind stage.
|
||||
type UnwindOption func(*UnwindOpts)
|
||||
|
||||
type UnwindOpts struct {
|
||||
PreserveNullAndEmptyArrays bool
|
||||
IncludeArrayIndex string
|
||||
}
|
||||
|
||||
// WithPreserveNullAndEmptyArrays tells $unwind to keep docs where the array is null/empty.
|
||||
func WithPreserveNullAndEmptyArrays() UnwindOption {
|
||||
return func(o *UnwindOpts) {
|
||||
o.PreserveNullAndEmptyArrays = true
|
||||
}
|
||||
}
|
||||
|
||||
// WithIncludeArrayIndex adds an array‐index field named idxField to each unwound doc.
|
||||
func WithIncludeArrayIndex(idxField string) UnwindOption {
|
||||
return func(o *UnwindOpts) {
|
||||
o.IncludeArrayIndex = idxField
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package builder
|
||||
|
||||
type Value interface {
|
||||
Build() any
|
||||
}
|
||||
@@ -0,0 +1,253 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"git.sendico.io/tech/sxchnge/shared/database/internal/builder"
|
||||
"git.sendico.io/tech/sxchnge/shared/database/record"
|
||||
"git.sendico.io/tech/sxchnge/shared/database/repository/builder"
|
||||
sharedmodel "git.sendico.io/tech/sxchnge/shared/model"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
func Query() builder.Query {
|
||||
return builderimp.NewQueryImp()
|
||||
}
|
||||
|
||||
func Filter(field string, value any) builder.Query {
|
||||
return Query().Filter(Field(field), value)
|
||||
}
|
||||
|
||||
func Field(baseName string) builder.Field {
|
||||
return builderimp.NewFieldImp(baseName)
|
||||
}
|
||||
|
||||
func Ref(field builder.Field) builder.Field {
|
||||
return builderimp.NewRefFieldImp(field)
|
||||
}
|
||||
|
||||
func RootRef() builder.Field {
|
||||
return builderimp.NewRootRef()
|
||||
}
|
||||
|
||||
func RemoveRef() builder.Field {
|
||||
return builderimp.NewRemoveRef()
|
||||
}
|
||||
|
||||
func Pipeline(stages ...bson.D) builder.Pipeline {
|
||||
return builderimp.NewPipelineImp(stages...)
|
||||
}
|
||||
|
||||
func IDField() builder.Field {
|
||||
return Field(storable.IDField)
|
||||
}
|
||||
|
||||
func NameField() builder.Field {
|
||||
return Field(sharedmodel.NameField)
|
||||
}
|
||||
|
||||
func DescrtiptionField() builder.Field {
|
||||
return Field(sharedmodel.DescriptionField)
|
||||
}
|
||||
|
||||
func IsArchivedField() builder.Field {
|
||||
return Field(storable.IsArchivedField)
|
||||
}
|
||||
|
||||
func IDFilter(ref bson.ObjectID) builder.Query {
|
||||
return Query().Filter(IDField(), ref)
|
||||
}
|
||||
|
||||
func ArchivedFilter() builder.Query {
|
||||
return IsArchivedFilter(true)
|
||||
}
|
||||
|
||||
func NotArchivedFilter() builder.Query {
|
||||
return IsArchivedFilter(false)
|
||||
}
|
||||
|
||||
func IsArchivedFilter(isArchived bool) builder.Query {
|
||||
return Query().Filter(IsArchivedField(), isArchived)
|
||||
}
|
||||
|
||||
func AccountField() builder.Field {
|
||||
return Field("accountRef")
|
||||
}
|
||||
|
||||
func AccountFilter(ref bson.ObjectID) builder.Query {
|
||||
return Query().Filter(AccountField(), ref)
|
||||
}
|
||||
|
||||
func StatusRefField() builder.Field {
|
||||
return Field("statusRef")
|
||||
}
|
||||
|
||||
func StatusRefFilter(ref bson.ObjectID) builder.Query {
|
||||
return Query().Filter(StatusRefField(), ref)
|
||||
}
|
||||
|
||||
func PriorityRefField() builder.Field {
|
||||
return Field("priorityRef")
|
||||
}
|
||||
|
||||
func PriorityRefFilter(ref bson.ObjectID) builder.Query {
|
||||
return Query().Filter(PriorityRefField(), ref)
|
||||
}
|
||||
|
||||
func IndexField() builder.Field {
|
||||
return Field("index")
|
||||
}
|
||||
|
||||
func IndexFilter(index int) builder.Query {
|
||||
return Query().Filter(IndexField(), index)
|
||||
}
|
||||
|
||||
func IndexOpFilter(index int, operation builder.MongoOperation) builder.Query {
|
||||
return Query().Comparison(IndexField(), operation, index)
|
||||
}
|
||||
|
||||
func Patch() builder.Patch {
|
||||
return builderimp.NewPatchImp()
|
||||
}
|
||||
|
||||
func Accumulator(operator builder.MongoOperation, value any) builder.Accumulator {
|
||||
return builderimp.NewAccumulator(operator, value)
|
||||
}
|
||||
|
||||
func GroupAccumulator(field builder.Field, acc builder.Accumulator) builder.GroupAccumulator {
|
||||
return builderimp.NewGroupAccumulator(field, acc)
|
||||
}
|
||||
|
||||
func Literal(value any) builder.Expression {
|
||||
return builderimp.NewLiteralExpression(value)
|
||||
}
|
||||
|
||||
func Projection(alias builder.Alias) builder.Projection {
|
||||
return builderimp.NewAliasProjection(alias)
|
||||
}
|
||||
|
||||
func IncludeField(field builder.Field) builder.Projection {
|
||||
return builderimp.IncludeField(field)
|
||||
}
|
||||
|
||||
func ExcludeField(field builder.Field) builder.Projection {
|
||||
return builderimp.ExcludeField(field)
|
||||
}
|
||||
|
||||
func ProjectionExpr(field builder.Field, expr builder.Expression) builder.Projection {
|
||||
return builderimp.NewProjectionExpr(field, expr)
|
||||
}
|
||||
|
||||
func NullAlias(lhs builder.Field) builder.Alias {
|
||||
return builderimp.NewNullAlias(lhs)
|
||||
}
|
||||
|
||||
func SimpleAlias(lhs, rhs builder.Field) builder.Alias {
|
||||
return builderimp.NewSimpleAlias(lhs, rhs)
|
||||
}
|
||||
|
||||
func ComplexAlias(lhs builder.Field, rhs []builder.Alias) builder.Alias {
|
||||
return builderimp.NewComplexAlias(lhs, rhs)
|
||||
}
|
||||
|
||||
func Aliases(aliases ...builder.Alias) builder.Alias {
|
||||
return builderimp.NewAliases(aliases...)
|
||||
}
|
||||
|
||||
func AddToSet(value builder.Expression) builder.Expression {
|
||||
return builderimp.AddToSet(value)
|
||||
}
|
||||
|
||||
func Size(value builder.Expression) builder.Expression {
|
||||
return builderimp.Size(value)
|
||||
}
|
||||
|
||||
func InRef(value builder.Field) builder.Expression {
|
||||
return builderimp.InRef(value)
|
||||
}
|
||||
|
||||
func In(values ...any) builder.Expression {
|
||||
return builderimp.In(values)
|
||||
}
|
||||
|
||||
func Cond(condition builder.Expression, ifTrue, ifFalse any) builder.Expression {
|
||||
return builderimp.NewCond(condition, ifTrue, ifFalse)
|
||||
}
|
||||
|
||||
func And(exprs ...builder.Expression) builder.Expression {
|
||||
return builderimp.NewAnd(exprs...)
|
||||
}
|
||||
|
||||
func Or(exprs ...builder.Expression) builder.Expression {
|
||||
return builderimp.NewOr(exprs...)
|
||||
}
|
||||
|
||||
func Type(expr builder.Expression) builder.Expression {
|
||||
return builderimp.NewType(expr)
|
||||
}
|
||||
|
||||
func Not(expression builder.Expression) builder.Expression {
|
||||
return builderimp.NewNot(expression)
|
||||
}
|
||||
|
||||
func Sum(expression builder.Expression) builder.Expression {
|
||||
return builderimp.NewSum(expression)
|
||||
}
|
||||
|
||||
func Assign(field builder.Field, expression builder.Expression) builder.Projection {
|
||||
return builderimp.NewAssignment(field, expression)
|
||||
}
|
||||
|
||||
func SetUnion(exprs ...builder.Expression) builder.Expression {
|
||||
return builderimp.NewSetUnion(exprs...)
|
||||
}
|
||||
|
||||
func Eq(left, right builder.Expression) builder.Expression {
|
||||
return builderimp.Eq(left, right)
|
||||
}
|
||||
|
||||
func Gt(left, right builder.Expression) builder.Expression {
|
||||
return builderimp.Gt(left, right)
|
||||
}
|
||||
|
||||
func Lt(left, right builder.Expression) builder.Expression {
|
||||
return builderimp.NewLt(left, right)
|
||||
}
|
||||
|
||||
func Array(expressions ...builder.Expression) builder.Array {
|
||||
return builderimp.NewArray(expressions...)
|
||||
}
|
||||
|
||||
func IfNull(cond, replacement builder.Expression) builder.Expression {
|
||||
return builderimp.NewIfNull(cond, replacement)
|
||||
}
|
||||
|
||||
func Each(exprs ...builder.Expression) builder.Expression {
|
||||
return builderimp.NewEach(exprs...)
|
||||
}
|
||||
|
||||
func Push(expression builder.Expression) builder.Expression {
|
||||
return builderimp.NewPush(expression)
|
||||
}
|
||||
|
||||
func Min(expression builder.Expression) builder.Expression {
|
||||
return builderimp.NewMin(expression)
|
||||
}
|
||||
|
||||
func Ne(left, right builder.Expression) builder.Expression {
|
||||
return builderimp.Ne(left, right)
|
||||
}
|
||||
|
||||
func Compute(field builder.Field, expression builder.Expression) builder.Expression {
|
||||
return builderimp.NewCompute(field, expression)
|
||||
}
|
||||
|
||||
func First(expr builder.Expression) builder.Expression {
|
||||
return builderimp.First(expr)
|
||||
}
|
||||
|
||||
func Value(value any) builder.Value {
|
||||
return builderimp.NewValue(value)
|
||||
}
|
||||
|
||||
func Exists(field builder.Field, exists bool) builder.Query {
|
||||
return Query().Comparison(field, builder.Exists, exists)
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"git.sendico.io/tech/sxchnge/shared/database/repository/builder"
|
||||
sharedmodel "git.sendico.io/tech/sxchnge/shared/model"
|
||||
)
|
||||
|
||||
// ApplyCursor adds pagination and archival filters to the provided query.
|
||||
func ApplyCursor(query builder.Query, cursor *sharedmodel.ViewCursor) builder.Query {
|
||||
if cursor == nil {
|
||||
return query
|
||||
}
|
||||
|
||||
query = query.Limit(cursor.Limit)
|
||||
query = query.Offset(cursor.Offset)
|
||||
query = query.Archived(cursor.IsArchived)
|
||||
|
||||
return query
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package repository
|
||||
|
||||
import "go.mongodb.org/mongo-driver/v2/mongo"
|
||||
|
||||
type DecodingFunc = func(r *mongo.Cursor) error
|
||||
@@ -0,0 +1,25 @@
|
||||
package repository
|
||||
|
||||
import "git.sendico.io/tech/sxchnge/shared/database/repository/builder"
|
||||
|
||||
type Sort int8
|
||||
|
||||
const (
|
||||
Asc Sort = 1
|
||||
Desc Sort = -1
|
||||
)
|
||||
|
||||
type Key struct {
|
||||
Field string
|
||||
Sort Sort // 1 or -1. 0 means “use Type”.
|
||||
Type IndexType // optional: "text", "2dsphere", ...
|
||||
}
|
||||
|
||||
type Definition struct {
|
||||
Keys []Key // mandatory, at least one element
|
||||
Unique bool // unique constraint?
|
||||
Sparse bool // sparse?
|
||||
TTL *int32 // seconds; nil means “no TTL”
|
||||
Name string // optional explicit name
|
||||
PartialFilter builder.Query // optional: partialFilterExpression for conditional indexes
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package repository
|
||||
|
||||
// IndexType represents a supported MongoDB index type.
|
||||
type IndexType string
|
||||
|
||||
const (
|
||||
// IndexTypeNotSet is a default index type
|
||||
IndexTypeNotSet IndexType = ""
|
||||
|
||||
// IndexTypeSingleField is a single-field index.
|
||||
IndexTypeSingleField IndexType = "single"
|
||||
|
||||
// IndexTypeCompound is a compound index on multiple fields.
|
||||
IndexTypeCompound IndexType = "compound"
|
||||
|
||||
// IndexTypeMultikey is an index on array fields (created automatically when needed).
|
||||
IndexTypeMultikey IndexType = "multikey"
|
||||
|
||||
// IndexTypeText is a text index for full-text search.
|
||||
IndexTypeText IndexType = "text"
|
||||
|
||||
// IndexTypeGeo2D is a legacy 2D geospatial index for planar geometry.
|
||||
IndexTypeGeo2D IndexType = "2d"
|
||||
|
||||
// IndexTypeGeo2DSphere is a 2dsphere geospatial index for GeoJSON data.
|
||||
IndexTypeGeo2DSphere IndexType = "2dsphere"
|
||||
|
||||
// IndexTypeHashed is a hashed index for sharding and efficient equality queries.
|
||||
IndexTypeHashed IndexType = "hashed"
|
||||
|
||||
// IndexTypeWildcard is a wildcard index to index all fields or subpaths.
|
||||
IndexTypeWildcard IndexType = "wildcard"
|
||||
|
||||
// IndexTypeClustered is a clustered index that orders the collection on the index key.
|
||||
IndexTypeClustered IndexType = "clustered"
|
||||
)
|
||||
@@ -0,0 +1,58 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.sendico.io/tech/sxchnge/shared/database/internal/repository"
|
||||
"git.sendico.io/tech/sxchnge/shared/database/record"
|
||||
"git.sendico.io/tech/sxchnge/shared/database/repository/builder"
|
||||
rd "git.sendico.io/tech/sxchnge/shared/database/repository/decoder"
|
||||
ri "git.sendico.io/tech/sxchnge/shared/database/repository/index"
|
||||
"git.sendico.io/tech/sxchnge/shared/database/transaction"
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
"go.mongodb.org/mongo-driver/v2/mongo"
|
||||
)
|
||||
|
||||
type (
|
||||
// FilterQuery selects documents to operate on.
|
||||
FilterQuery = builder.Query
|
||||
// PatchDoc defines field/value modifications for partial updates.
|
||||
PatchDoc = builder.Patch
|
||||
)
|
||||
|
||||
type Repository interface {
|
||||
Aggregate(ctx context.Context, builder builder.Pipeline, decoder rd.DecodingFunc) error
|
||||
Insert(ctx context.Context, obj storable.Storable, getFilter builder.Query) error
|
||||
InsertMany(ctx context.Context, objects []storable.Storable) error
|
||||
Get(ctx context.Context, id bson.ObjectID, result storable.Storable) error
|
||||
FindOneByFilter(ctx context.Context, builder builder.Query, result storable.Storable) error
|
||||
FindFirstByFilter(ctx context.Context, builder builder.Query, result storable.Storable) error
|
||||
FindManyByFilter(ctx context.Context, builder builder.Query, decoder rd.DecodingFunc) error
|
||||
// FindAllByFilter decodes all matching documents into result, which must be a pointer to a slice.
|
||||
FindAllByFilter(ctx context.Context, builder builder.Query, result any) error
|
||||
CountByFilter(ctx context.Context, builder builder.Query) (int64, error)
|
||||
Update(ctx context.Context, obj storable.Storable) error
|
||||
// ReplaceOneByFilter replaces one matching document with obj and reports whether a document matched the filter.
|
||||
// The repository must persist obj as provided and must not mutate its timestamps or identity before replacement.
|
||||
ReplaceOneByFilter(ctx context.Context, filter builder.Query, obj storable.Storable) (bool, error)
|
||||
// Upsert replaces the document identified by obj ID, inserting it when no document exists.
|
||||
Upsert(ctx context.Context, obj storable.Storable) error
|
||||
// Patch applies partial updates defined by patch to the document identified by id.
|
||||
Patch(ctx context.Context, id bson.ObjectID, patch PatchDoc) error
|
||||
// PatchOneByFilter atomically patches one document matching filter and decodes the updated document into result.
|
||||
PatchOneByFilter(ctx context.Context, filter FilterQuery, patch PatchDoc, result storable.Storable) (bool, error)
|
||||
// PatchMany applies partial updates defined by patch to all documents matching filter and returns the number of updated documents.
|
||||
PatchMany(ctx context.Context, filter FilterQuery, patch PatchDoc) (int, error)
|
||||
Delete(ctx context.Context, id bson.ObjectID) error
|
||||
DeleteMany(ctx context.Context, query builder.Query) error
|
||||
CreateIndex(def *ri.Definition) error
|
||||
DropIndex(ctx context.Context, name string) error
|
||||
ListIndexDefinitions(ctx context.Context) ([]*ri.Definition, error)
|
||||
ListIDs(ctx context.Context, query builder.Query) ([]bson.ObjectID, error)
|
||||
WithTransaction(ctx context.Context, cb transaction.Callback) (any, error)
|
||||
Collection() string
|
||||
}
|
||||
|
||||
func CreateMongoRepository(db *mongo.Database, collection string) Repository {
|
||||
return repositoryimp.NewMongoRepository(db, collection)
|
||||
}
|
||||
Reference in new issue
Block a user