Documentation
¶
Overview ¶
Package r3bson is the data-store dialect that translates r3 query types (r3.FilterSpec, r3.SortSpec, and friends) into MongoDB bson.D documents. It is the MongoDB counterpart of r3sql.
Index ¶
- Variables
- func CursorToBSON(values r3.CursorValues, sorts r3.Sorts, direction r3.CursorDirection) (bson.D, error)
- func FieldToBSON(f *r3.FieldSpec) string
- func FieldsToBSON(fields r3.Fields) bson.D
- func FilterToBSON(f *r3.FilterSpec) (bson.D, error)
- func FiltersToBSON(filters r3.Filters) (bson.D, error)
- func IsErrDialectorFailure(err error) bool
- func SortToBSON(s *r3.SortSpec) (bson.E, error)
- func SortsToBSON(sorts r3.Sorts) (bson.D, error)
- type BSONOperator
Constants ¶
This section is empty.
Variables ¶
var ErrBSONDialectorFailed = errors.New("bson dialector failed")
ErrBSONDialectorFailed is the sentinel wrapping every r3bson failure.
Functions ¶
func CursorToBSON ¶
func CursorToBSON(values r3.CursorValues, sorts r3.Sorts, direction r3.CursorDirection) (bson.D, error)
CursorToBSON builds a keyset pagination filter from decoded cursor values and the active sorts. A single column yields {col: {$lt: v}}; multiple columns yield the lexicographic $or/$and expansion, e.g.
{$or: [{created_at: {$lt: v1}}, {$and: [{created_at: {$eq: v1}}, {id: {$gt: v2}}]}]}
$gt vs $lt is chosen per column from its sort direction, flipped for a backward cursor.
func FieldToBSON ¶
FieldToBSON converts a FieldSpec to a BSON field name string.
func FieldsToBSON ¶
FieldsToBSON converts r3.Fields to a bson.D inclusion projection (each field set to 1). _id is always included, even when not listed.
func FilterToBSON ¶
func FilterToBSON(f *r3.FilterSpec) (bson.D, error)
FilterToBSON converts a FilterSpec to a bson.D filter document.
func FiltersToBSON ¶
FiltersToBSON converts r3.Filters into a combined bson.D, joining multiple filters with $and.
func IsErrDialectorFailure ¶
IsErrDialectorFailure reports whether err is a r3bson failure.
func SortToBSON ¶
SortToBSON converts a SortSpec to a bson.E element (field: 1 or field: -1).
Types ¶
type BSONOperator ¶
type BSONOperator string
BSONOperator represents a MongoDB query operator (e.g. "$eq", "$regex", "$in").
const ( BSONOperatorEq BSONOperator = "$eq" BSONOperatorNe BSONOperator = "$ne" BSONOperatorGt BSONOperator = "$gt" BSONOperatorGte BSONOperator = "$gte" BSONOperatorLt BSONOperator = "$lt" BSONOperatorLte BSONOperator = "$lte" BSONOperatorIn BSONOperator = "$in" BSONOperatorNin BSONOperator = "$nin" BSONOperatorRegex BSONOperator = "$regex" BSONOperatorExists BSONOperator = "$exists" BSONOperatorOptions BSONOperator = "$options" BSONOperatorNot BSONOperator = "$not" BSONOperatorAnd BSONOperator = "$and" BSONOperatorOr BSONOperator = "$or" // Aggregation-expression operators used by $expr to lower the time-component // filter operators (weekday_in, tod_between), which have no plain-query form. BSONOperatorExpr BSONOperator = "$expr" BSONOperatorDayOfWeek BSONOperator = "$dayOfWeek" BSONOperatorHour BSONOperator = "$hour" BSONOperatorMinute BSONOperator = "$minute" BSONOperatorAdd BSONOperator = "$add" BSONOperatorMultiply BSONOperator = "$multiply" )
List of supported BSON operators.
func OperatorToBSON ¶
func OperatorToBSON(op r3.FilterOperatorSpec) (BSONOperator, error)
OperatorToBSON converts a FilterOperatorSpec to a BSONOperator.
func (BSONOperator) String ¶
func (op BSONOperator) String() string
String so we implement fmt.Stringer.