Skip to content

Commit 7f5028a

Browse files
committed
fix: add coverage, add license, gofmt -s all files, update readme
1 parent 754f9be commit 7f5028a

10 files changed

+196
-57
lines changed

LICENSE

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright (c) 2019 Xavier Tremblay St-Germain <https://xaviertremblay.com>
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

+35-15
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,34 @@
11
# Kendo data query for Go
22

3-
[![Build Status](https://travis-ci.org/XavierTS/kendo-data-query.svg)](https://travis-ci.org/XavierTS/kendo-data-query)
4-
[![codecov](https://codecov.io/gh/XavierTS/kendo-data-query/branch/master/graph/badge.svg)](https://codecov.io/gh/XavierTS/kendo-data-query)
5-
[![GoDoc](https://godoc.org/github.com/XavierTS/kendo-data-query?status.svg)](https://godoc.org/github.com/XavierTS/kendo-data-query)
3+
[![Build Status](https://travis-ci.org/x22n/kendo-data-query.svg)](https://travis-ci.org/x22n/kendo-data-query)
4+
[![codecov](https://codecov.io/gh/x22n/kendo-data-query/branch/master/graph/badge.svg)](https://codecov.io/gh/x22n/kendo-data-query)
5+
[![GoDoc](https://godoc.org/github.com/x22n/kendo-data-query?status.svg)](https://godoc.org/github.com/x22n/kendo-data-query)
6+
[![Go Report Card](https://goreportcard.com/badge/github.com/x22n/kendo-data-query)](https://goreportcard.com/report/github.com/x22n/kendo-data-query)
67

7-
## Limitations
8+
Go (Golang) library to parse and apply Kendo data query on a MongoDB database using mgo.
9+
10+
---
11+
12+
- [Kendo data query for Go](#kendo-data-query-for-go)
13+
- [Install](#install)
14+
- [Examples](#examples)
15+
- [Handler example](#handler-example)
16+
- [DataResult example](#dataresult-example)
17+
- [Limitations](#limitations)
18+
- [Roadmap](#roadmap)
19+
20+
---
21+
22+
## Install
823

9-
* Does not support multiple sorts on base columns BUT supports multiple sorted groups
10-
* Only supports `and` logic between filters
11-
* Only supports `avg` and `sum` aggregates
24+
```sh
25+
go get -u github.com/x22n/kendo-data-query
26+
```
27+
28+
## Examples
1229

13-
## Usage
30+
### Handler example
1431

15-
#### Handler example
1632
```go
1733
func MyHandler(w http.ResponseWriter, r *http.Request) {
1834
ds, err := kendo.NewDataStateFromRequest(ctx.Request)
@@ -33,11 +49,15 @@ func MyHandler(w http.ResponseWriter, r *http.Request) {
3349
{"data":[{"title":"cat","due":1.98},{"title":"dog","due":8.21},...],"total":325}
3450
```
3551

52+
## Limitations
53+
54+
- Does not support multiple sorts on base columns BUT supports multiple sorted groups
55+
- Only supports `and` logic between filters
56+
- Only supports `avg` and `sum` aggregates
57+
3658
## Roadmap
3759

38-
* Better godoc
39-
* Better path coverage
40-
* Support for `or` logic between filters
41-
* Support for complex/nested filters
42-
* Better error handling on `Apply(collection)`
43-
* Support for more aggregates
60+
- Better godoc
61+
- Support for `or` logic between filters
62+
- Support for complex/nested filters
63+
- Support for more aggregates

apply.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import (
88
"github.com/globalsign/mgo/bson"
99
)
1010

11-
func (d *DataState) Apply(collection mgo.Collection) (dataResult DataResult) {
12-
if err := d.parse(); err != nil {
11+
// Apply will parse the request values and retrieves the DataResult from a collection
12+
func (d *DataState) Apply(collection mgo.Collection) (dataResult DataResult, err error) {
13+
if err = d.parse(); err != nil {
1314
return
1415
}
1516

@@ -22,12 +23,11 @@ func (d *DataState) Apply(collection mgo.Collection) (dataResult DataResult) {
2223

2324
data := []interface{}{}
2425
err = aggregate.All(&data)
25-
fmt.Println(err)
2626

2727
return DataResult{
2828
Data: data,
2929
Total: total,
30-
}
30+
}, nil
3131
}
3232

3333
func (d *DataState) getBasePipeline() (pipeline []bson.M) {
@@ -297,7 +297,7 @@ func (d *DataState) getFilter() (filter bson.M) {
297297
filter = bson.M{}
298298

299299
for _, f := range d.Filter.Filters {
300-
f.Filter(filter)
300+
f.filter(filter)
301301
}
302302

303303
return
@@ -325,7 +325,7 @@ func (d *DataState) getPaging() (paging []bson.M) {
325325
page := d.Page - 1
326326

327327
return []bson.M{
328-
bson.M{"$skip": page * d.PageSize},
329-
bson.M{"$limit": d.PageSize},
328+
{"$skip": page * d.PageSize},
329+
{"$limit": d.PageSize},
330330
}
331331
}

0 commit comments

Comments
 (0)