A library to parse and validate advanced REST API query parameters including filters, pagination, sorting, grouping, and search with logical operators. RQL takes a Golang struct and a JSON string as input and returns a validated object that can be used to prepare SQL statements using raw SQL or ORM query builders.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/raystack/salt/llms.txt
Use this file to discover all available pages before exploring further.
Installation
Features
- Filter Support: Complex filtering with operators (eq, neq, like, gt, lt, etc.)
- Pagination: Offset and limit support
- Sorting: Multi-field sorting with asc/desc ordering
- Grouping: Group by multiple fields
- Search: Fuzzy search across specified columns
- Type Validation: Validates data types using struct tags
- Operator Validation: Ensures operators are valid for each data type
Data Structures
Query
Represents a complete query with filters, sorting, pagination, and more.Array of filter conditions to apply
Fields to group results by
Number of records to skip (for pagination)
Maximum number of records to return
Search term for fuzzy search across columns
Array of sort criteria
Filter
Represents a single filter condition.Field name to filter on (must match struct tag)
Comparison operator (e.g.,
eq, neq, like, gt, gte, lt, lte, in, notin)Value to compare against (type must match field data type)
Sort
Represents sorting criteria for a field.Field name to sort by
Sort order:
"asc" or "desc"Functions
ValidateQuery
Validates a query against a struct definition with RQL tags.The query to validate
A struct with
rql tags defining valid fields and typesValidation error if query is invalid, nil if valid
GetDataTypeOfField
Retrieves the data type of a field from the struct definition.Name of the field to check
Struct with RQL tags
The data type:
"number", "string", "datetime", or "bool"Error if field not found or invalid data type
Supported Data Types
Define data types using thetype parameter in RQL tags:
Numeric values (int, uint, float, etc.)Operators:
eq, neq, gt, lt, gte, lteString valuesOperators:
eq, neq, like, in, notin, notlike, empty, notemptyISO 8601 datetime strings (RFC3339 format)Operators:
eq, neq, gt, lt, gte, lteBoolean valuesOperators:
eq, neqStruct Tags
Define validation rules using therql struct tag:
Field name as used in queries (defaults to struct field name)
Data type:
number, string, datetime, or boolMinimum value (for number types) - planned feature
Maximum value (for number types) - planned feature
Constants
Query JSON Format
Frontend should send parameters in this JSON schema:Complete Example with SQL Generation
Error Handling
The library returns detailed validation errors for:- Invalid field names that don’t exist in the struct
- Invalid operators for the field’s data type
- Type mismatches between filter values and field types
- Invalid datetime formats (must be RFC3339)
- Invalid sort orders (must be “asc” or “desc”)
Future Improvements
- Operator mapping to SQL operators (currently relies on query builders like GoQU)
- Support for
minandmaxvalidation on numeric values - More complex query expressions with AND/OR grouping