r3bson

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: MIT Imports: 6 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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 ExcludeFieldsToBSON added in v0.4.0

func ExcludeFieldsToBSON(fields r3.Fields) bson.D

ExcludeFieldsToBSON converts r3.Fields to a bson.D exclusion projection (each field set to 0) - the subtractive form of FieldsToBSON. _id is never excluded, the mirror of FieldsToBSON always including it: an entity returned without its identity cannot be patched, deleted, or linked. MongoDB rejects a projection mixing 1s and 0s, so the two forms are never combined - r3 refuses that pairing upstream with r3.ErrProjectionConflict.

func FieldToBSON

func FieldToBSON(f *r3.FieldSpec) string

FieldToBSON converts a FieldSpec to a BSON field name string.

func FieldsToBSON

func FieldsToBSON(fields r3.Fields) bson.D

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

func FiltersToBSON(filters r3.Filters) (bson.D, error)

FiltersToBSON converts r3.Filters into a combined bson.D, joining multiple filters with $and.

func IsErrDialectorFailure

func IsErrDialectorFailure(err error) bool

IsErrDialectorFailure reports whether err is a r3bson failure.

func SortToBSON

func SortToBSON(s *r3.SortSpec) (bson.E, error)

SortToBSON converts a SortSpec to a bson.E element (field: 1 or field: -1).

func SortsToBSON

func SortsToBSON(sorts r3.Sorts) (bson.D, error)

SortsToBSON converts a slice of SortSpec to a bson.D sort document.

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"

	// BSONOperatorExpr and the aggregation-expression operators below are 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.

Jump to

Keyboard shortcuts

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