service backend
All checks were successful
ci/woodpecker/push/db Pipeline was successful
ci/woodpecker/push/nats Pipeline was successful

This commit is contained in:
Stephan D
2025-11-07 18:35:26 +01:00
parent 20e8f9acc4
commit 62a6631b9a
537 changed files with 48453 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
package builder
import "go.mongodb.org/mongo-driver/bson"
type Accumulator interface {
Build() bson.D
}
type GroupAccumulator interface {
Build() bson.D
}

View File

@@ -0,0 +1,8 @@
package builder
import "go.mongodb.org/mongo-driver/bson"
type Alias interface {
Field() Field
Build() bson.D
}

View File

@@ -0,0 +1,7 @@
package builder
import "go.mongodb.org/mongo-driver/bson"
type Array interface {
Build() bson.A
}

View File

@@ -0,0 +1,5 @@
package builder
type Expression interface {
Build() any
}

View File

@@ -0,0 +1,7 @@
package builder
type Field interface {
Dot(field string) Field
CopyWith(field string) Field
Build() string
}

View File

@@ -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"
)

View File

@@ -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"
)

View File

@@ -0,0 +1,16 @@
package builder
import "go.mongodb.org/mongo-driver/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
}

View File

@@ -0,0 +1,24 @@
package builder
import (
"github.com/tech/sendico/pkg/mservice"
"go.mongodb.org/mongo-driver/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
}

View File

@@ -0,0 +1,7 @@
package builder
import "go.mongodb.org/mongo-driver/bson"
type Projection interface {
Build() bson.D
}

View File

@@ -0,0 +1,24 @@
package builder
import (
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/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.FindOptions
}

View File

@@ -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 arrayindex field named idxField to each unwound doc.
func WithIncludeArrayIndex(idxField string) UnwindOption {
return func(o *UnwindOpts) {
o.IncludeArrayIndex = idxField
}
}

View File

@@ -0,0 +1,5 @@
package builder
type Value interface {
Build() any
}