github.com/wearetheledger/go-couchdb-query-engine
go get github.com/wearetheledger/go-couchdb-query-engine

github.com/wearetheledger/go-couchdb-query-engine

CouchDB query implementation in Golang for in-memory object querying

by wearetheledger

v0.0.0-20181028083156-74445b61f15e (see all)License:Apache-2.0
go get github.com/wearetheledger/go-couchdb-query-engine
Readme

go-couchdb-query-engine

CouchDB query implementation in Golang for in-memory object querying

Build status: Build Status

Features

  • skip
  • limit
  • selector

Selector

The selector query accepts following couchdb operators:

  • all
  • and
  • elematch
  • eq
  • exists
  • gt
  • gte
  • in
  • lt
  • lte
  • mod
  • ne
  • nin
  • nor
  • not
  • or
  • regex
  • size
  • type

Example code

Data

var TestData = map[string]interface{}{
    "MARBLE1": map[string]interface{}{
        "objectType": "MARBLE",
        "owner":      "bob",
        "size":       3,
        "previousOwners": []string{
            "alice",
            "donald",
        },
        "family": map[string]interface{}{
            "name":   "colored",
            "origin": "spain",
        },
    },
    "MARBLE2": map[string]interface{}{
        "objectType": "MARBLE",
        "owner":      "alice",
        "size":       1,
        "previousOwners": []string{
            "donald",
        },
        "family": map[string]interface{}{
            "name":   "white",
            "origin": "france",
        },
        "verification": []interface{}{
            map[string]interface{}{
                "organizationId": "marbles inspectors inc.",
                "checkedAt":      "2017-12-18T12:11:34.171Z",
                "score":          5,
            },
        },
    },
    "MARBLE3": map[string]interface{}{
        "objectType": "MARBLE",
        "owner":      "arnold",
        "size":       5,
        "previousOwners": []string{
            "alice",
        },
        "family": map[string]interface{}{
            "name":   "striped",
            "origin": "america",
        },
        "verification": []interface{}{
            map[string]interface{}{
                "organizationId": "marbles ID inc.",
                "checkedAt":      "2017-12-18T12:11:34.171Z",
                "score":          3,
            },
            map[string]interface{}{
                "organizationId": "marbles ID inc.",
                "checkedAt":      "2016-12-18T12:11:34.171Z",
                "score":          7,
            },
        },
    },
}

Method

res, err := query.ParseCouchDBQuery(TestData, map[string]interface{}{
            "selector": map[string]interface{}{
                "size": map[string]interface{}{
                    "$eq": 3,
                },
            },
        })

Response

StateCouchDBQueryResult{
    StateCouchDBQueryObject{
        Key: "MARBLE0",
        Value: map[string]interface{}{
            "objectType": "MARBLE",
            "owner":      "bob",
            "size":       3,
            "previousOwners": []string{
                "alice",
                "donald",
            },
            "family": map[string]interface{}{
                "name":   "colored",
                "origin": "spain",
            },
        },
    },
}

GitHub Stars

11

LAST COMMIT

4yrs ago

MAINTAINERS

0

CONTRIBUTORS

3

OPEN ISSUES

0

OPEN PRs

0
VersionTagPublished
v0.0.0-20180619091610-0077c9455028
3yrs ago
v0.0.0-20181028083156-74445b61f15e
3yrs ago
No alternatives found
No tutorials found
Add a tutorial