{"_id":"@allstar/reql-builder","_rev":"2-b7eff417bd29f52cae5cfaff217ade25","name":"@allstar/reql-builder","description":"Dynamic filter builder for rethinkdb and reql","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"@allstar/reql-builder","version":"1.0.0","description":"Dynamic filter builder for rethinkdb and reql","main":"index.js","scripts":{"test":"tap -J -Rclassic test --cov","test:ci":"tap -J -Rclassic test --cov","posttest:ci":"tap coverage-report=lcov && cat ./coverage/lcov.info | ./node_modules/.bin/codacy-coverage"},"repository":{"type":"git","url":"git+ssh://git@bitbucket.org/hitlist/reql-builder.git"},"keywords":["rethink","rethinkdb","reql","builder"],"author":{"name":"Eric Satterwhite","email":"esatterwhite@wi.rr.com"},"license":"MIT","homepage":"https://bitbucket.org/hitlist/reql-builder#readme","devDependencies":{"codacy-coverage":"^2.0.3","tap":"^11.0.1","thinky":"^2.3.9"},"gitHead":"5b991d25880e94537b433671333576b551ccd68d","_id":"@allstar/reql-builder@1.0.0","_npmVersion":"5.5.1","_nodeVersion":"8.9.1","_npmUser":{"name":"esatterwhite","email":"esatterwhite@wi.rr.com"},"dist":{"integrity":"sha512-AaeuZiqwguG0y6oBI5EXAdjQ9NsyOHQrW2TH2z4mQhawKgryEag7bDeQv/yVKTlAnxHaJvrh/jFEzGcZvpl7UQ==","shasum":"effbcc91119074d7409cb7e0de4551a1a4cb940c","tarball":"https://registry.npmjs.org/@allstar/reql-builder/-/reql-builder-1.0.0.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIAlrPoKCSRUTY7ffmNNeuWPzSMoScIPnPaEaEiRrWkbSAiEA4gt6WLwVeYJp/9ksGQGlWvRjGiI3N2EBmNOA/n96roM="}]},"maintainers":[{"name":"esatterwhite","email":"esatterwhite@wi.rr.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/reql-builder-1.0.0.tgz_1515959838034_0.5232925007585436"}},"1.0.1":{"name":"@allstar/reql-builder","version":"1.0.1","description":"Dynamic filter builder for rethinkdb and reql","main":"index.js","scripts":{"test":"tap -J -Rclassic test --cov","test:ci":"tap -J -Rclassic test --cov","posttest:ci":"tap coverage-report=lcov && cat ./coverage/lcov.info | ./node_modules/.bin/codacy-coverage"},"repository":{"type":"git","url":"git+https://bitbucket.org/hitlist/reql-builder.git"},"keywords":["rethink","rethinkdb","reql","builder"],"author":{"name":"Eric Satterwhite","email":"esatterwhite@wi.rr.com"},"license":"MIT","homepage":"https://bitbucket.org/hitlist/reql-builder#readme","devDependencies":{"codacy-coverage":"^2.0.3","tap":"^11.0.1","thinky":"^2.3.9"},"gitHead":"4a35f948ecc9bbefb268569bc6c6ae2d32dd1014","_id":"@allstar/reql-builder@1.0.1","_npmVersion":"5.5.1","_nodeVersion":"8.9.1","_npmUser":{"name":"esatterwhite","email":"esatterwhite@wi.rr.com"},"dist":{"integrity":"sha512-8A+nFEs+7wZUkgKJdOLa/jEZlzRZ2LsAQfwZ6FfB55e3sylOT7De7Feu2yldhmFV5RddICvSNeLZWGItVbPfJQ==","shasum":"27e291c8afc3b15a57b790a3f30cbd79a9eea9f6","tarball":"https://registry.npmjs.org/@allstar/reql-builder/-/reql-builder-1.0.1.tgz","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIEAW7CIq0N1Bevxf/44sSNLL9bUT5lBHcnjsFkSicTLSAiAYw/h83wZK2vdtRmMc2dAWghbnZOW1dyIuyqEMLLx4dw=="}]},"maintainers":[{"name":"esatterwhite","email":"esatterwhite@wi.rr.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/reql-builder-1.0.1.tgz_1516027215045_0.36549440724775195"}}},"readme":"# reql-builder\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/322bc6c1eb0c4ec790fbed6d01d580af)](https://www.codacy.com/app/esatterwhite/reql-builder?utm_source=hitlist@bitbucket.org&amp;utm_medium=referral&amp;utm_content=hitlist/reql-builder&amp;utm_campaign=Badge_Grade)\n[![Codacy Badge](https://api.codacy.com/project/badge/Coverage/322bc6c1eb0c4ec790fbed6d01d580af)](https://www.codacy.com/app/esatterwhite/reql-builder?utm_source=hitlist@bitbucket.org&amp;utm_medium=referral&amp;utm_content=hitlist/reql-builder&amp;utm_campaign=Badge_Coverage)\n\nDynamic filter builder for [rethinkdbdash](https://github.com/neumino/rethinkdbdash) inspired by https://github.com/node-tastypie/tastypie-rethink\n\n### Paging\nYou can use a number of special query string params to control how data is paged on the list endpoint. Namely -\n\n* `limit` - Page size ( default 25 )\n* `offset` - The starting point in the list\n\n`limit=25&offset=50` would be the start of page 3\n\n### Sorting\nsorting is handled query param orderby where you can pass it the name of a field to sort on. Sorting is descending by default. Specifying a negetive field ( -<FOO> ) would flip the order\n\n### Advanced Filtering\nYou might have noticed the filtering field on the schema. One of the things that makes an API \"Good\" is the ability to use query and filter the data to get very specific subsets of data. Tastypie exposes this through the query string as field and filter combinations. By default, the resource doesn't have anything enabled, you need to specify which filters are allowed on which fields, or specify 1 to allow everything\n\n#### Filter Types\n\n| Filter      | function                                         |\n| ------------|------------------------------------------------- |\n| gt          | greater than                                     |\n| gte         | greater than or equal to                         |\n| lt          | less than                                        |\n| lte         | less than or equal to                            |\n| in          | Value in set ( [ 1,2,3 ])                        |\n| nin         | Value Not in set                                 |\n| size        | Size of set ( array length )                     |\n| startswith  | Case Sensitive string match                      |\n| istartswith | Case Insensitive string match                    |\n| endswith    | Case Sensitive string match                      |\n| iendswith   | Case Insensitive string match                    |\n| contains    | Case Sensitive global string match               |\n| icontains   | Case Insensitive global string match             |\n| exact ( = ) | Exact Case Sensitive string match                |\n| iexact      | Exact Case Insensitive string match              |\n| isnull      | matches null values                              |\n| month       | Matches date values on a specific month          |\n| day         | Matches date values on a speciec day of the week |\n| year        | Matches date values on a specific year           |\n| all         | Matches all elements in an array                 |\n| range       | Matches dates withing a specified range          |\n| ne          | not equal to                                     |\n\nFilters are added by appending a double underscore ``__`` and the filter type to the end of a field name. Given our example, if we wanted to find people who were older than 25, we would use the following URI syntax\n\n```bash\nhttp://localhost:3000/api/v1/user?age__gt=25\n```\nFilters are additive for a given field. For example, if we we only wanted people where we between 25 and 45, we would just add another filter\n\n```bash\nhttp://localhost:3000/api/v1/user?age__gt=25&age__lt=45\n```\n\nThe same double underscore `__` syntax is used to access nested fields where the filter is always the last parameter. So we could find people whos age was  **greater than** 25, **less than** 45 and whose Company Name **starts with** `W`\n\n```bash\nhttp://localhost:3000/api/v1/user?age__gt=25&age__lt=45&company__name__istartswith=w\n```\n\nexpressions with no filters will use the default `exact` filter\n\n```bash\nhttp://localhost:3000/api/v1/user?age=44\n```\n\n## API\n\n### filter(r `<rethinkdbdash>`, filters `<Object>`): `Query`\n\n* `r` - a rethinkdb dash connection w/ a default database configured\n* `filters` - an object to generate a query from. Typically a result from querystring.parse\n* **returns** a rethink filter query suitable to pass to `r.filter`\n\n\nGiven a table of user records\n\n```javascript\n{\n  \"email\": \"billybob@bobsfarms.biz\"\n, name: {\n    \"first\": \"Billy\"\n  , \"last\": \"Bob\"\n  }\n}\n```\n\n```javascript\nconst qs = require('querystring')\nconst {filter} = require('@allstar/reql-builder')\nconst r = require('rethinkdbdash')({db: 'test'})\n\n// emails w/ .biz\n// name.first = ^bi\n\nconst filters = filter(r, {\n  email__icontains: '.biz'\n, name__first__istartswith: 'bi'\n})\n\n// same as\n\nconst opts = qs.parse('email__contains=.biz&name__first__istartswith=bi')\nconst filters = filter(r, opts)\n\n\nr.table('users').filter(filters).then((results) => {\n  console.log(results)\n})\n```\n\n### toResponse(r `<rethinkdbdash>`, table `<String>` [,options] `<Object>`): Promise\n\nreturns a paginated list of records suitable for an api response directly from the database\n\n#### options\n\n- **limit** `<number>` [25] the maximum number of records to return\n- **offset** `<number>` [0] The number of records to skip over\n- **filters** `[object] Filters to apply the the dataset before pagination\n- **orderby** `[string]` The filed and direction (`-/+`) to sort the records by\n- **orderby_index** `[string]` the name of the index to use to sort by - it should include the field\n\n* With out an index to order by performance can degrade very quickly with large datasets\n\n```javascript\nconst toResponse = require('@allstar/reql-builder')\nconst r = require('rethinkdbdash')({db: 'test'})\n\ntoResponse(r, 'users', {\n  orderby: '-id'\n, orderby_index: 'user_id_idx'\n, limit: 5\n, offset: 5 // page 2\n, filters: {email__iendswith: '.biz'}\n})\n.then(console.log)\n\n{\n  \"meta\": {\n    total: 7\n  , limit: 5\n  , offset: 5\n  , next: null\n  , previous: null\n  }\n, \"data\" :[\n    {id: 6, email: 'fake-6@test.biz'}\n  , {id: 7, email: 'fake-7@test.biz'}\n  ]\n}\n```\n","maintainers":[{"name":"esatterwhite","email":"esatterwhite@wi.rr.com"}],"time":{"modified":"2022-04-04T13:34:49.975Z","created":"2018-01-14T19:57:19.007Z","1.0.0":"2018-01-14T19:57:19.007Z","1.0.1":"2018-01-15T14:40:15.114Z"},"homepage":"https://bitbucket.org/hitlist/reql-builder#readme","keywords":["rethink","rethinkdb","reql","builder"],"repository":{"type":"git","url":"git+https://bitbucket.org/hitlist/reql-builder.git"},"author":{"name":"Eric Satterwhite","email":"esatterwhite@wi.rr.com"},"license":"MIT","readmeFilename":"README.md"}