A couchdb 2.0 query parser, using jison
npm install --save jouch
import parse from 'jouch'
import PouchDB from 'pouchdb'
import pouchdb-find from 'pouchdb-find'
PouchDB.plugin(pouchdb-find)
const db = new PouchDB('/path/to/pouch')
const selector = parse('id != null')
db.find({
selector: selector
}).then(res => {
// results
})
// TODO: add couchdb usage example
expression | result |
---|---|
== |
$eq |
!= |
$ne |
>= |
$gte |
<= |
$lte |
> |
$gt |
< |
$lt |
and |
$and |
or |
$or |
not |
$not |
has |
$elemMatch |
e.g.
const selector = jouch('age >= 18 and skills has "javascript"')
would parse to
{ "$and": [
{ "age": {"$gte": 18}},
{ "$elemMatch": {"skills": {"$eq": "javascript"}}}
]
}