Skip to content

Commit

Permalink
refactor: rename to rql
Browse files Browse the repository at this point in the history
  • Loading branch information
whoAbhishekSah committed Feb 17, 2025
1 parent b5051ea commit 0d1aaf1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
16 changes: 8 additions & 8 deletions qp/README.md → rql/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# QP (Query parser)
# RQL (Rest Query Language)

A library to parse support advanced REST API query parameters like (filter, pagination, sort, group, search) and logical operators on the keys (like eq, neq, like, gt, lt etc)

Expand Down Expand Up @@ -32,18 +32,18 @@ Frontend should send the parameters and operator like this schema to the backend
}
```

The `qp` library can be used to parse this json, validate it and returns a Struct containing all the info to generate the operations and values for SQL.
The `rql` library can be used to parse this json, validate it and returns a Struct containing all the info to generate the operations and values for SQL.

The validation happens via stuct tags defined on your model. Example:

```golang
type Organization struct {
Id int `qp:"type=number,min=10,max=200"`
BillingPlanName string `qp:"type=string"`
CreatedAt time.Time `qp:"type=datetime"`
MemberCount int `qp:"type=number"`
Title string `qp:"type=string"`
Enabled bool `qp:"type=bool"`
Id int `rql:"type=number,min=10,max=200"`
BillingPlanName string `rql:"type=string"`
CreatedAt time.Time `rql:"type=datetime"`
MemberCount int `rql:"type=number"`
Title string `rql:"type=string"`
Enabled bool `rql:"type=bool"`
}

```
Expand Down
4 changes: 2 additions & 2 deletions qp/parser/parser.go → rql/parser.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package parser
package rql

import (
"fmt"
Expand All @@ -15,7 +15,7 @@ var validBoolOperations = []string{"eq", "neq"}
var validDatetimeOperations = []string{"eq", "neq", "gt", "gt", "gte", "lte"}
var validSortOrder = []string{"asc", "desc"}

const TAG = "qp"
const TAG = "rql"

type Query struct {
Filters []Filter `json:"filters"`
Expand Down
10 changes: 5 additions & 5 deletions qp/parser/parser_test.go → rql/parser_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package parser
package rql

import (
"testing"
"time"
)

type TestStruct struct {
ID int32 `qp:"type=number"`
Name string `qp:"type=string"`
IsActive bool `qp:"type=bool"`
CreatedAt time.Time `qp:"type=datetime"`
ID int32 `rql:"type=number"`
Name string `rql:"type=string"`
IsActive bool `rql:"type=bool"`
CreatedAt time.Time `rql:"type=datetime"`
}

func TestValidateQuery(t *testing.T) {
Expand Down

0 comments on commit 0d1aaf1

Please sign in to comment.