query

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2025 License: BSD-2-Clause Imports: 8 Imported by: 4 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenAQLFilterStatement

func GenAQLFilterStatement(prms *StatementParameters) (string, error)

GenAQLFilterStatement generates an AQL (ArangoDB Query Language) compatible filter query statement from the provided StatementParameters.

Unlike GenQualifiedAQLFilterStatement, this function expects field names to be mapped to non-qualified database field names and handles field access differently, prefixing them with document/vertex variables (e.g., doc.field, vertex.field).

This function handles standard operators, date comparisons, and array operations, and supports both document-based queries and graph traversal queries through the Document and Vertex parameters.

Parameters:

  • prms: A StatementParameters struct containing the filter map, filters, document variable name, and optional vertex variable name

Returns the generated AQL filter statement as a string and any error encountered.

func GenQualifiedAQLFilterStatement

func GenQualifiedAQLFilterStatement(
	fmap map[string]string,
	filters []*Filter,
) (string, error)

GenQualifiedAQLFilterStatement generates an AQL (ArangoDB Query Language) compatible filter query statement where the fields map is expected to contain namespaced (fully qualified) mapping to database fields, like:

{
	"tag": "doc.label",
	"name": "doc.level.identifier"
}

This function handles standard operators, date comparisons, and array operations, generating the appropriate LET statements and filter conditions in AQL syntax. It also manages logical operators (AND/OR) between filter expressions and ensures proper parenthetical grouping. Parameters:

  • fmap: A map of field names to their fully qualified database field paths
  • filters: A slice of Filter structures containing the filter criteria

Types

type AQLFilterParams added in v0.6.0

type AQLFilterParams struct {
	// Map of fields to database paths
	Fmap map[string]string `validate:"required,min=1"`
	// Slice of Filter structs
	Filters []*Filter `validate:"required,min=1,dive"`
}

AQLFilterParams defines validation for GenQualifiedAQLFilterStatement parameters

type Filter

type Filter struct {
	// Field of the object on which the filter will be applied
	Field string `validate:"required"`
	// Type of filter for matching or exclusion
	Operator string `validate:"required,operator_validation"`
	// The value to match or exclude
	Value string `validate:"required"`
	// Logic for combining multiple filter expressions, usually "AND" or "OR", "," (comma) for OR, ";" (semicolon) for AND
	Logic string `validate:"omitempty"`
}

Filter is a container for filter parameters.

func ParseFilterString

func ParseFilterString(fstr string) ([]*Filter, error)

ParseFilterString parses a predefined filter string into a slice of Filter structures. The filter string follows a specific format for field comparisons: field operator value[logic], for example "name==john,age>20;email=~gmail" where ',' represents OR and ';' represents AND. The filter string specification is defined in the corresponding protocol buffer definition.

Operators supported include standard comparisons (==, !=, >, <, >=, <=, =~, !~), date operators ($==, $>, $<, $>=, $<=), and array operators (@==, @=~, @!~, @!=).

Returns an error if the filter string contains invalid operators.

type StatementParameters

type StatementParameters struct {
	// Map of filters to database fields
	Fmap map[string]string `validate:"required"`
	// Slice of Filter structs, contains all necessary items for AQL statement
	Filters []*Filter `validate:"required,dive"`
	// The variable used for looping inside a collection (i.e. the "s" in "FOR s IN stock")
	Doc string `validate:"required"`
	// The variable used for looping inside a graph (i.e. the "v" in "FOR v IN 1..1 OUTBOUND s GRAPH 'xyz'")
	Vert string
}

StatementParameters is a container for elements needed in the AQL statement.

Jump to

Keyboard shortcuts

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