{"id":18871864,"url":"https://github.com/foxifyjs/foxify-restify-odin","last_synced_at":"2026-04-06T03:31:36.088Z","repository":{"id":33288005,"uuid":"157623992","full_name":"foxifyjs/foxify-restify-odin","owner":"foxifyjs","description":"Easily restify odin databases","archived":false,"fork":false,"pushed_at":"2023-01-04T17:44:01.000Z","size":990,"stargazers_count":3,"open_issues_count":12,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-29T19:03:59.574Z","etag":null,"topics":["filter","foxify","middleware","odin","restify","sort"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/foxifyjs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-11-14T23:19:30.000Z","updated_at":"2021-11-09T11:50:48.000Z","dependencies_parsed_at":"2023-01-15T00:23:49.123Z","dependency_job_id":null,"html_url":"https://github.com/foxifyjs/foxify-restify-odin","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foxifyjs%2Ffoxify-restify-odin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foxifyjs%2Ffoxify-restify-odin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foxifyjs%2Ffoxify-restify-odin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/foxifyjs%2Ffoxify-restify-odin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/foxifyjs","download_url":"https://codeload.github.com/foxifyjs/foxify-restify-odin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247714526,"owners_count":20983893,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["filter","foxify","middleware","odin","restify","sort"],"created_at":"2024-11-08T05:27:47.820Z","updated_at":"2026-04-06T03:31:31.053Z","avatar_url":"https://github.com/foxifyjs.png","language":"TypeScript","funding_links":["https://www.patreon.com/ardalanamini","https://www.buymeacoffee.com/ardalanamini"],"categories":[],"sub_categories":[],"readme":"# foxify-restify-odin \u003c!-- omit in toc --\u003e\n\nEasily restify odin databases\n\n[![Npm Version](https://img.shields.io/npm/v/foxify-restify-odin.svg)](https://www.npmjs.com/package/foxify-restify-odin)\n[![Node Version](https://img.shields.io/node/v/foxify-restify-odin.svg)](https://nodejs.org)\n[![TypeScript Version](https://img.shields.io/npm/types/foxify-restify-odin.svg)](https://www.typescriptlang.org)\n[![Package Quality](https://npm.packagequality.com/shield/foxify-restify-odin.svg)](https://packagequality.com/#?package=foxify-restify-odin)\n[![Npm Total Downloads](https://img.shields.io/npm/dt/foxify-restify-odin.svg)](https://www.npmjs.com/package/foxify-restify-odin)\n[![Npm Monthly Downloads](https://img.shields.io/npm/dm/foxify-restify-odin.svg)](https://www.npmjs.com/package/foxify-restify-odin)\n[![Open Issues](https://img.shields.io/github/issues-raw/foxifyjs/foxify-restify-odin.svg)](https://github.com/foxifyjs/foxify-restify-odin/issues?q=is%3Aopen+is%3Aissue)\n[![Closed Issues](https://img.shields.io/github/issues-closed-raw/foxifyjs/foxify-restify-odin.svg)](https://github.com/foxifyjs/foxify-restify-odin/issues?q=is%3Aissue+is%3Aclosed)\n[![Known Vulnerabilities](https://snyk.io/test/github/foxifyjs/foxify-restify-odin/badge.svg?targetFile=package.json)](https://snyk.io/test/github/foxifyjs/foxify-restify-odin?targetFile=package.json)\n[![Dependencies Status](https://david-dm.org/foxifyjs/foxify-restify-odin.svg)](https://david-dm.org/foxifyjs/foxify-restify-odin)\n[![Pull Requests](https://img.shields.io/badge/PRs-Welcome-brightgreen.svg)](https://github.com/foxifyjs/foxify-restify-odin/pulls)\n[![License](https://img.shields.io/github/license/foxifyjs/foxify-restify-odin.svg)](https://github.com/foxifyjs/foxify-restify-odin/blob/master/LICENSE)\n[![Build Status](https://api.travis-ci.com/foxifyjs/foxify-restify-odin.svg?branch=master)](https://travis-ci.com/foxifyjs/foxify-restify-odin)\n[![Coverage Status](https://codecov.io/gh/foxifyjs/foxify-restify-odin/branch/master/graph/badge.svg)](https://codecov.io/gh/foxifyjs/foxify-restify-odin)\n[![Github Stars](https://img.shields.io/github/stars/foxifyjs/foxify-restify-odin.svg?style=social\u0026label=Stars)](https://github.com/foxifyjs/foxify-restify-odin)\n[![Github Forks](https://img.shields.io/github/forks/foxifyjs/foxify-restify-odin.svg?style=social\u0026label=Fork)](https://github.com/foxifyjs/foxify-restify-odin)\n\n## Table on Contents \u003c!-- omit in toc --\u003e\n\n- [Getting Started](#getting-started)\n  - [Prerequisites](#prerequisites)\n  - [Installation](#installation)\n  - [Usage](#usage)\n- [Documentation](#documentation)\n  - [Filters](#filters)\n  - [include](#include)\n  - [sort](#sort)\n  - [skip](#skip)\n  - [limit](#limit)\n- [Versioning](#versioning)\n- [Authors](#authors)\n- [License](#license)\n- [Support](#support)\n\n## Getting Started\n\n### Prerequisites\n\n- [Node.js](https://nodejs.org/en/download) `8.12` or higher is required.\n- [foxify](https://github.com/foxifyjs/foxify) `0.10.20` or higher is required.\n- [@foxify/odin](https://github.com/foxifyjs/odin) `0.8.0` or higher is required.\n\n### Installation\n\n```bash\nnpm i -s foxify-restify-odin\n```\n\n### Usage\n\n```javascript\nconst Foxify = require('foxify');\nconst restify = require('foxify-restify-odin');\nconst User = require('./models/User');\n\nlet app = new Foxify();\n\napp.get('/users', restify(User), async (req, res) =\u003e {\n  res.json({\n    users: await req.fro.query.get(),\n    total_users: await req.fro.counter.count(),\n  });\n});\n\napp.start();\n```\n\n## Documentation\n\n```typescript\ntype Operator = \"lt\" | \"lte\" | \"eq\" | \"ne\" | \"gte\" | \"gt\" |\n  \"exists\" | \"in\" | \"nin\" | \"bet\" | \"nbe\" | \"like\" | \"nlike\";\n\ninterface FilterObject {\n  field: string;\n  operator: Operator;\n  value: string | number | boolean | any[] | object | Date;\n}\n\ninterface Filter {\n  and?: Array\u003cFilterObject | Filter\u003e;\n  or?: Array\u003cFilterObject | Filter\u003e;\n  has?: string | { relation: string, filter: Filter | FilterObject };\n}\n\ninterface Query {\n  filter?: Filter | FilterObject;\n  include?: string[];\n  sort?: string[];\n  skip?: number;\n  limit?: number;\n}\n\ninterface RouteOptions {\n  pre?: Foxify.Handler | Foxify.Handler[];\n  post?: Foxify.Handler | Foxify.Handler[];\n}\n\ninterface RoutesOptions {\n  index: RouteOptions \u0026 { lean?: boolean; } | false;\n  count: RouteOptions | false;\n  store: RouteOptions | false;\n  show: RouteOptions | false;\n  update: RouteOptions | false;\n  delete: RouteOptions | false;\n}\n\ninterface Options {\n  name: string;\n  prefix: string;\n  qs: QSParseOptions;\n  defaults: Query;\n  pre: Foxify.Handler | Foxify.Handler[];\n  routes: Partial\u003cRoutesOptions\u003e;\n}\n\nrestify(model: typeof Odin, options: Partial\u003crestify.Options\u003e = {}): Router;\n```\n\nThis module's middleware parses url query string and executes a query on the given model accordingly and passes the `query` to you (since you might need to do some modifications on the query, too)\n\nIt also passes a `counter` which is exactly like `query` but without applying `skip`, `limit`, `sort` just because you might want to send a total count in your response as well\n\nLastly it passes the a `decoded` key in `req.fro` which is the parsed query string that is used in the middleware\n\n**Stringify all query params using [qs](https://www.npmjs.com/package/qs) default options**\n\nAll the possible query modifiers are explained as a single modification but they all can be used together\n\n`/users?sort%5B0%5D=age`\n\n### Filters\n\n```javascript\nqs.stringify({\n  filter: {\n    field: \"username\",\n    operator: \"eq\",\n    value: \"ardalanamini\",\n  }\n})\n```\n\n```javascript\nqs.stringify({\n  filter: {\n    or: [\n      {\n        field: \"username\",\n        operator: \"eq\",\n        value: \"ardalanamini\",\n      },\n      {\n        and: [\n          {\n            field: \"age\",\n            operator: \"gte\",\n            value: 18,\n          },\n          {\n            field: \"email\",\n            operator: \"exists\",\n            value: true,\n          },\n        ],\n      },\n    ],\n  },\n})\n```\n\nfilter can be a single filter object or `and`/`or` of Array\\\u003cfilter object\\\u003e\n\npossible operators:\n\n`lt` | `lte` | `eq` | `ne` | `gte` | `gt` | `exists` | `in` | `nin` | `bet` | `nbe` | `like` | `nlike`\n\n### include\n\n```javascript\nqs.stringify({\n  include: [\n    \"relation1\",\n    \"relation2.subRelation1.subRelation2\",\n  ]\n})\n```\n\n### sort\n\n```javascript\nqs.stringify({\n  sort: [\n    \"field1\", // same as \"+field1\"\n    \"-field2\",\n    \"+field3\",\n  ]\n})\n```\n\n### skip\n\n```javascript\nqs.stringify({\n  skip: 100,\n})\n```\n\n### limit\n\n```javascript\nqs.stringify({\n  limit: 10,\n})\n```\n\n## Versioning\n\nWe use [SemVer](http://semver.org) for versioning. For the versions available, see the [tags on this repository](https://github.com/foxifyjs/foxify-restify-odin/tags).\n\n## Authors\n\n- **Ardalan Amini** - *Owner/Developer* - [@ardalanamini](https://github.com/ardalanamini)\n\nSee also the list of [contributors](https://github.com/foxifyjs/foxify-restify-odin/contributors) who participated in this project.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details\n\n## Support\n\nIf my work helps you, please consider\n\n[![Become A Patron](https://c5.patreon.com/external/logo/become_a_patron_button.png)](https://www.patreon.com/ardalanamini)\n\n[![Buy Me A Coffee](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/ardalanamini)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffoxifyjs%2Ffoxify-restify-odin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffoxifyjs%2Ffoxify-restify-odin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffoxifyjs%2Ffoxify-restify-odin/lists"}