Skip to content

xompass/lbq

Repository files navigation

Loopback Query Filter

Introduction

This golang project parses a loopback 3 like filter.

Usage

package main

import "github.com/xompass/lbq"

func main() {
	filter, err:= lbq.ParseFilter("<your loopback filter json string>")
	
	//...
}

Examples

Fields

var filter = lbq.Filter {
	Fields: lbq.Fields{
		"field1": true,
		"field2": true,
		"field3": false,
	},
}

Limit and Skip

var filter = lbq.Filter {
	Limit: 10,
	Skip: 5,
}

Order

var filter = lbq.Filter {
	Order: []lbq.Order{
		{
			Field: "field1",
			Direction: "ASC",
		},
		{
			Field: "field2",
			Direction: "DESC",
		},
	},
}

Where

var filter = lbq.Filter {
	Where: lbq.Where{
	"field1": "value1",
	"field2": lbq.Where {
		"gt": 10,
	},
	"and": []lbq.AndOrCondition{
			{ "field3": "value3" },
			{ "field4": true },
		},
	},
}

Include

var filter = lbq.Filter {
	Include: []lbq.Include{
		{
			Relation: "relation1",
			Scope: &lbq.Filter{
				Fields: lbq.Fields{
					"field1": true,
					"field2": true,
				},
			},
		},
		{
			Relation: "relation2",
			Scope: lbq.Filter{
				Fields: lbq.Where{
					"field3": "value3",
				},
			},
		},
		{
			Relation: "relation3",
		},
	},
}