package filter

import "github.com/datastax/astra-db-go/v2/astra/filter"

Package filter defines filtering options for Astra DB queries.

Index

Types

type A

type A []any

A represents a slice/array of filters to be applied to an Astra DB query. Use this in conjunction with F if you want to pass filters as they appear in JSON data.

Example:

filters := filter.F{
	"$and": filter.A{
		filter.F{"$or": filter.A{
			filter.F{"is_checked_out": false},
			filter.F{"number_of_pages": filter.F{"$lt": 300}},
		}},
		filter.F{"$or": filter.A{
			filter.F{"genres": filter.F{"$in": filter.A{"Fantasy", "Romance"}}},
			filter.F{"publication_year": filter.F{"$gte": 2002}},
		}},
	},
}

type F

type F map[string]any

F represents a map of filters to be applied to an Astra DB query. Use this in conjunction with A if you want to pass filters as they appear in JSON data.

Example:

filters := filter.F{
	"$and": filter.A{
		filter.F{"$or": filter.A{
			filter.F{"is_checked_out": false},
			filter.F{"number_of_pages": filter.F{"$lt": 300}},
		}},
		filter.F{"$or": filter.A{
			filter.F{"genres": filter.F{"$in": filter.A{"Fantasy", "Romance"}}},
			filter.F{"publication_year": filter.F{"$gte": 2002}},
		}},
	},
}

See [FilterOperator] for available operators.

type Filter

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

Filter represents a collection of filters. Compose filters with package-level functions like Eq, Gt, And, etc. Example:

filters := filter.And(
	filter.Or(
		filter.Eq("is_checked_out", false),
		filter.Lt("number_of_pages", 300),
	),
	filter.Or(
		filter.In("genres", "Fantasy", "Romance"),
		filter.Gte("publication_year", 2002),
	),
)
func All
func All(key string, vals ...any) Filter
func And
func And(children ...Filter) Filter
func Eq
func Eq(key string, val any) Filter
func Exists
func Exists(key string, val bool) Filter
func Gt
func Gt(key string, val any) Filter
func Gte
func Gte(key string, val any) Filter
func In
func In(key string, vals ...any) Filter
func LexicalMatch
func LexicalMatch(val string) Filter

LexicalMatch creates a filter that matches documents against the collection's reserved $lexical field. Lexicographical matching is only available for collections with lexical enabled.

Example usage:

filters := filter.LexicalMatch("tree hill")
func Lt
func Lt(key string, val any) Filter
func Lte
func Lte(key string, val any) Filter
func Ne
func Ne(key string, val any) Filter
func Nin
func Nin(key string, vals ...any) Filter
func Not
func Not(child Filter) Filter
func Or
func Or(children ...Filter) Filter
func Size
func Size(key string, val int) Filter
func (Filter) MarshalAstraRaw
func (f Filter) MarshalAstraRaw(ctx serdes.EncodeCtx, dst []byte) ([]byte, error)

type Filterable

type Filterable interface {
	// contains filtered or unexported methods
}

Filterable is implemented by types that can be used as query filters.

type Operator

type Operator string

Operator represents the operation type (Eq, Gt, etc.)

const (
	OpAnd              Operator = "$and"
	OpOr               Operator = "$or"
	OpNot              Operator = "$not"
	OpGreaterThan      Operator = "$gt"
	OpGreaterThanEqual Operator = "$gte"
	OpLessThan         Operator = "$lt"
	OpLessThanEqual    Operator = "$lte"
	OpEqual            Operator = "$eq"
	OpNotEqual         Operator = "$ne"
	OpIn               Operator = "$in"
	OpNotIn            Operator = "$nin"
	OpExists           Operator = "$exists"
	OpAll              Operator = "$all"
	OpSize             Operator = "$size"
	OpLexical          Operator = "$lexical"
	OpMatch            Operator = "$match"
)