Skip to content
/ rql Public

A rest filter parser for Go that returns built queries

License

Notifications You must be signed in to change notification settings

dvaldivia/rql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

A rest filter parser for Go that returns built queries

Topics

Resources

License

Stars

Watchers

Forks

Languages