Giter VIP home page Giter VIP logo

rest-query-parser's People

Contributors

dennigogo avatar gerricom avatar timsolov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

rest-query-parser's Issues

Removing filters with OR statements leads to incorrect Where construction

All cases in single test case set

func Test_RemoveOrEntries(t *testing.T) {
	type testCase struct {
		name string
		urlQuery string
		filterToRemove string
		wantWhere             string
	}
	tests := []testCase{
		{
			name: "should fix OR statements after removing EndOR filter with 2 items",
			urlQuery: "?test1[eq]=test10|test2[eq]=test10",
			filterToRemove: "test2",
			wantWhere: "test1 = ?",
		},
		{
			name: "should fix OR statements after removing StartOR filter with 2 items",
			urlQuery: "?test1[eq]=test10|test2[eq]=test10",
			filterToRemove: "test1",
			wantWhere: "test2 = ?",
		},
		{
			name: "should fix OR statements after removing StartOR filter with 3 items",
			urlQuery: "?test1[eq]=test10|test2[eq]=test10|test3[eq]=test10",
			filterToRemove: "test1",
			wantWhere: "(test2 = ? OR test3 = ?)",
		},
		{
			name: "should fix OR statements after removing EndOR filter with 3 items",
			urlQuery: "?test1[eq]=test10|test2[eq]=test10|test3[eq]=test10",
			filterToRemove: "test3",
			wantWhere: "(test1 = ? OR test2 = ?)",
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			// Arrange
			URL, _ := url.Parse(tt.urlQuery)
			q := rqp.NewQV(nil, rqp.Validations{
				"test1": nil,
				"test2": nil,
				"test3": nil,
			})
			_ = q.SetUrlQuery(URL.Query()).Parse()

			// Act
			_ = q.RemoveFilter(tt.filterToRemove)

			// Assert
			assert.Equal(t, tt.wantWhere, q.WHERE())
		})
	}
}

Readme Example gives me an error

Hello! NIce library, very comprehensive functions. I've tried but i got an error from example in Readme.

q2, _ := rqp.NewParse(r.URL.Query(), rqp.Validations{
		"limit:required": rqp.MinMax(10, 100),  // limit must present in the Query part and must be between 10 and 100 (default: Min(1))
		"sort":           rqp.In("id", "name"), // sort could be or not in the query but if it is present it must be equal to "in" or "name"
		"s":              rqp.In("one", "two"), // filter: s - string and equal
		"id:int":         nil,                  // filter: id is integer without additional validation
		"i:int": func(value interface{}) error { // filter: custom func for validating
			if value.(int) > 1 && value.(int) < 10 {
				return nil
			}
			return errors.New("i: must be greater then 1 and lower then 10")
		},
		"email": nil,
		"name":  nil,
	})

URL looks like: ?sort=+name,-id&limit=10&id=1&i[eq]=5&s[eq]=one&email[like]=*tim*|name[like]=*tim*

Error: s[eq]: filter not found

If i remove s[eq] parameter from url query, then i got an error: sort: validation not found

If i remove sort parameter from url query, then i got an error: id: filter not found

Can you tell what i'm doing wrong?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.