package filter
import "github.com/datastax/astra-db-go/v2/astra/filter"
Package filter defines filtering options for Astra DB queries.
Index
- type A
- type F
-
type Filter
- func All(key string, vals ...any) Filter
- func And(children ...Filter) Filter
- func Eq(key string, val any) Filter
- func Exists(key string, val bool) Filter
- func Gt(key string, val any) Filter
- func Gte(key string, val any) Filter
- func In(key string, vals ...any) Filter
- func LexicalMatch(val string) Filter
- func Lt(key string, val any) Filter
- func Lte(key string, val any) Filter
- func Ne(key string, val any) Filter
- func Nin(key string, vals ...any) Filter
- func Not(child Filter) Filter
- func Or(children ...Filter) Filter
- func Size(key string, val int) Filter
- func (f Filter) MarshalAstraRaw(ctx serdes.EncodeCtx, dst []byte) ([]byte, error)
- type FilterOperator
- type Filterable
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 FilterOperator
type FilterOperator string
FilterOperator represents the operation type (Eq, Gt, etc.)
const ( OpAnd FilterOperator = "$and" OpOr FilterOperator = "$or" OpNot FilterOperator = "$not" OpGreaterThan FilterOperator = "$gt" OpGreaterThanEqual FilterOperator = "$gte" OpLessThan FilterOperator = "$lt" OpLessThanEqual FilterOperator = "$lte" OpEqual FilterOperator = "$eq" OpNotEqual FilterOperator = "$ne" OpIn FilterOperator = "$in" OpNotIn FilterOperator = "$nin" OpExists FilterOperator = "$exists" OpAll FilterOperator = "$all" OpSize FilterOperator = "$size" OpLexical FilterOperator = "$lexical" OpMatch FilterOperator = "$match" )
type Filterable
type Filterable interface { // contains filtered or unexported methods }
Filterable is implemented by types that can be used as query filters.