rql

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 19, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

README

RQL

REST Query Language

A library to introduce filters that can be passed by the client to the server via a query parameter using SQL like WHERE statements and getting a goqu []goqu.Expression in return.

Why?

Often applications building REST APIs need to expire a generic way to filter on top of existing resources, allowing the flexibility to filter by any field in the table, however coming up with a whole new syntax for such use case is complicated, on top of that you need to build the proper WHERE statement for a SQL query that is safe, RQL Filter addresses this.

RQL provides a way to safely and easily parse a filter statement and build a []goqu.Expression expression.

Examples

A query passed via GET or POST such as

field1='value1' AND (field2='value2' AND field3='value3')

woul yield the following expressions

[]goqu.Expression{
    goqu.C("field1").Eq("value1"),
    goqu.And([]goqu.Expression{
        goqu.C("field2").Eq("value2"),
        goqu.C("field3").Eq("value3"),
    }...),
}

TODOs

  • Pass list of valid fields to parser
  • Support dot-walking to related tables

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseFilter

func ParseFilter(rawFilters string) ([]goqu.Expression, error)

Types

type AstVisitor

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

func (*AstVisitor) VisitPost

func (v *AstVisitor) VisitPost(expr tree.Expr) (newNode tree.Expr)

func (*AstVisitor) VisitPre

func (v *AstVisitor) VisitPre(expr tree.Expr) (recurse bool, newExpr tree.Expr)

Jump to

Keyboard shortcuts

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