{"id":13781201,"url":"https://github.com/lookinlab/adonis-lucid-filter","last_synced_at":"2026-01-31T20:07:43.905Z","repository":{"id":32573031,"uuid":"136889979","full_name":"lookinlab/adonis-lucid-filter","owner":"lookinlab","description":"Addon for filtering AdonisJS Lucid ORM","archived":false,"fork":false,"pushed_at":"2025-01-04T13:30:24.000Z","size":181,"stargazers_count":157,"open_issues_count":2,"forks_count":12,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-10-19T00:16:04.189Z","etag":null,"topics":["adonis-filter","adonis-lucid","adonis-lucid-filter","adonisjs","dynamic-filters","lucid-filters","model-filter","model-filters"],"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/lookinlab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-06-11T07:29:24.000Z","updated_at":"2025-09-08T15:30:35.000Z","dependencies_parsed_at":"2024-01-15T04:07:10.557Z","dependency_job_id":"60289a1b-8d29-43e1-ac0b-6b9b86bbd486","html_url":"https://github.com/lookinlab/adonis-lucid-filter","commit_stats":{"total_commits":187,"total_committers":3,"mean_commits":"62.333333333333336","dds":0.03743315508021394,"last_synced_commit":"f44be59291599139d2af02e01b6149c8bd12fdf7"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"purl":"pkg:github/lookinlab/adonis-lucid-filter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lookinlab%2Fadonis-lucid-filter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lookinlab%2Fadonis-lucid-filter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lookinlab%2Fadonis-lucid-filter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lookinlab%2Fadonis-lucid-filter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lookinlab","download_url":"https://codeload.github.com/lookinlab/adonis-lucid-filter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lookinlab%2Fadonis-lucid-filter/sbom","scorecard":{"id":598682,"data":{"date":"2025-08-11","repo":{"name":"github.com/lookinlab/adonis-lucid-filter","commit":"2a4a6de4a6c09fdeb41fcb0f2a01194c05393661"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.5,"checks":[{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE.md:0","Info: FSF or OSI recognized license: MIT License: LICENSE.md:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-08-20T23:48:32.933Z","repository_id":32573031,"created_at":"2025-08-20T23:48:32.934Z","updated_at":"2025-08-20T23:48:32.934Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28952600,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-31T18:30:42.805Z","status":"ssl_error","status_checked_at":"2026-01-31T18:30:19.593Z","response_time":128,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["adonis-filter","adonis-lucid","adonis-lucid-filter","adonisjs","dynamic-filters","lucid-filters","model-filter","model-filters"],"created_at":"2024-08-03T18:01:23.843Z","updated_at":"2026-01-31T20:07:43.886Z","avatar_url":"https://github.com/lookinlab.png","language":"TypeScript","funding_links":[],"categories":["Packages","Databases, ORMs, Migrations \u0026 Seeding"],"sub_categories":[],"readme":"# Adonis Lucid Filter\n\u003e Works with AdonisJS v6\n\n[![npm-image]][npm-url] [![license-image]][license-url] [![typescript-image]][typescript-url]\n\nThis addon adds the functionality to filter Lucid Models\n\u003e Inspired by [EloquentFilter](https://github.com/Tucker-Eric/EloquentFilter)\n\n## Versions\n\n\u003e **Note**: Check before install :point_down:\n\n| adonis-lucid-filter                 | @adonisjs/lucid     |\n|-------------------------------------|---------------------|\n| ^5.\\*.*                             | ^20.\\*.*            |\n| ^4.\\*.*                             | \u003c=18.\\*.*           |\n| ^3.\\*.* (`@filterable()` decorator) | ^15.\\*.*            |\n| ^2.\\*.*                             | 14.\\*.*             |\n\n- Docs [for **Adonis v5**](https://github.com/lookinlab/adonis-lucid-filter/tree/v4)\n- Docs [for **Adonis v4**](https://github.com/lookinlab/adonis-lucid-filter/tree/v1)\n- Docs [for `@filterable()` decorator](https://github.com/lookinlab/adonis-lucid-filter/tree/v3)\n\n## Introduction\nExample, we want to return a list of users filtered by multiple parameters. When we navigate to:\n\n`/users?name=Tony\u0026lastName=\u0026companyId=2\u0026industry=5`\n\n`request.all()` or `request.qs()` will return:\n\n```json\n{\n  \"name\": \"Tony\",\n  \"lastName\": \"\",\n  \"companyId\": 2,\n  \"industry\": 5\n}\n```\n\nTo filter by all those parameters we would need to do something like:\n\n```ts\nimport type { HttpContext } from '@adonisjs/core/http'\nimport User from '#models/user'\n\nexport default class UsersController {\n  async index({ request }: HttpContext): Promise\u003cUser[]\u003e {\n    const { companyId, lastName, name, industry } = request.qs()\n  \n    const query = User.query().where('company_id', +companyId)\n\n    if (lastName) {\n      query.where('last_name', 'LIKE', `%${lastName}%`)\n    }\n    if (name) {\n      query.where(function () {\n        this.where('first_name', 'LIKE', `%${name}%`)\n          .orWhere('last_name', 'LIKE', `%${name}%`)\n      })\n    }\n    return query.exec()\n  }\n\n}\n```\n\nTo filter that same input with Lucid Filters:\n\n```ts\nimport type { HttpContext } from '@adonisjs/core/http'\nimport User from '#models/user'\n\nexport default class UsersController {\n  async index({ request }: HttpContext): Promise\u003cUser[]\u003e {\n    return User.filter(request.qs()).exec()\n  }\n}\n```\n\n## Installation\n\nMake sure to install it using `npm`, `yarn` or `pnpm`.\n\n```bash\n# npm\nnpm i adonis-lucid-filter\n\n# yarn\nyarn add adonis-lucid-filter\n\n# pnpm\npnpm add adonis-lucid-filter\n```\n\nAfter install call `configure`:\n\n```bash\nnode ace configure adonis-lucid-filter\n```\n\n## Usage\n\nMake sure to register the provider and commands inside `adonisrc.ts` file.\n\n```ts\nproviders: [\n  // ...\n  () =\u003e import('adonis-lucid-filter/provider'),\n],\ncommands: [\n  // ...\n  () =\u003e import('adonis-lucid-filter/commands')\n]\n```\n\n### Generating The Filter\n\u003e Only available if you have added `adonis-lucid-filter/commands` in `commands` array in your `adonisrc.ts'\n\nYou can create a model filter with the following ace command:\n\n```bash\nnode ace make:filter user\n```\n\nWhere `user` is the Lucid Model you are creating the filter for. This will create `app/models/filters/user_filter.js`\n\n### Defining The Filter Logic\nDefine the filter logic based on the camel cased input key passed to the `filter()` method.\n\n- Empty strings are ignored\n- `setup()` will be called regardless of input\n- `_id` is dropped from the end of the input to define the method so filtering `user_id` would use the `user()` method\n- Input without a corresponding filter method are ignored\n- The value of the key is injected into the method\n- All values are accessible through the `this.$input` a property\n- All QueryBuilder methods are accessible in `this.$query` object in the model filter class.\n\nTo define methods for the following input:\n\n```json\n{\n  \"companyId\": 5,\n  \"name\": \"Tony\",\n  \"mobilePhone\": \"888555\"\n}\n```\n\nYou would use the following methods:\n\n```ts\nimport { BaseModelFilter } from 'adonis-lucid-filter'\nimport type { ModelQueryBuilderContract } from '@adonisjs/lucid/types/model'\nimport User from '#models/user'\n\nexport default class UserFilter extends BaseModelFilter {\n  declare $query: ModelQueryBuilderContract\u003ctypeof User\u003e\n  \n  static blacklist: string[] = ['secretMethod']\n\n  // This will filter 'companyId', 'company_id' OR 'company'\n  company(id: number) {\n    this.$query.where('company_id', id)\n  }\n\n  name(name: string) {\n    this.$query.where((builder) =\u003e {\n      builder\n        .where('first_name', 'LIKE', `%${name}%`)\n        .orWhere('last_name', 'LIKE', `%${name}%`)\n    })\n  }\n\n  mobilePhone(phone: string) {\n    this.$query.where('mobile_phone', 'LIKE', `${phone}%`)\n  }\n\n  secretMethod(secretParameter: any) {\n    this.$query.where('some_column', true)\n  }\n}\n```\n\n#### Blacklist\n\nAny methods defined in the `blacklist` array will not be called by the filter.\nThose methods are normally used for internal filter logic.\n\nThe `whitelistMethod()` methods can be used to dynamically blacklist methods.\n\nExample:\n```ts\nsetup($query) {\n  this.whitelistMethod('secretMethod')\n  this.$query.where('is_admin', true)\n}\n```\n\u003e `setup()` not may be async\n\n\u003e **Note:** All methods inside `setup()` will be called every time `filter()` is called on the model\n\nIn the example above `secretMethod()` will not be called, even if there is a `secret_method` key in the input object.\nIn order to call this method it would need to be whitelisted dynamically:\n\n#### Static properties\n\n```ts\nexport default class UserFilter extends BaseModelFilter {\n  // Blacklisted methods\n  static blacklist: string[] = []\n  \n  // Dropped `_id` from the end of the input\n  // Doing this would allow you to have a `company()` filter method as well as a `companyId()` filter method.\n  static dropId: boolean = true\n  \n  // Doing this would allow you to have a mobile_phone() filter method instead of mobilePhone().\n  // By default, mobilePhone() filter method can be called thanks to one of the following input key:\n  // mobile_phone, mobilePhone, mobile_phone_id, mobilePhoneId\n  static camelCase: boolean = true\n}\n```\n\n### Applying The Filter To A Model\n\n```ts\nimport UserFilter from '#models/filters/user_filter'\nimport { compose } from '@adonisjs/core/helpers'\nimport { Filterable } from 'adonis-lucid-filter'\n\nexport default class User extends compose(BaseModel, Filterable) {\n  static $filter = () =\u003e UserFilter\n\n  // ...columns and props\n}\n```\n\nThis gives you access to the `filter()` method that accepts an object of input:\n\n```ts\nimport type { HttpContext } from '@adonisjs/core/http'\nimport User from '#models/user'\n\nexport default class UsersController {\n  async index({ request }: HttpContext): Promise\u003cUser[]\u003e {\n    return User.filter(request.qs()).exec()\n  }\n\n  // or with paginate method\n\n  async index({ request }: HttpContext): Promise\u003cModelPaginatorContract\u003cUser\u003e\u003e {\n    const { page = 1, ...input } = request.qs()\n    return User.filter(input).paginate(page, 15)\n  }\n}\n```\n\n### Dynamic Filters\n\nYou can define the filter dynamically by passing the filter to use as the second parameter of the filter() method.\nDefining a filter dynamically will take precedent over any other filters defined for the model.\n\n```ts\nimport type { HttpContext } from '@adonisjs/core/http'\nimport AdminFilter from '#models/filters/admin_filter'\nimport UserFilter from '#models/filters/user_filter'\n\nexport default class UsersController {\n  async index({ request, auth }: HttpContext): Promise\u003cUser[]\u003e {\n    const filter = auth.user.isAdmin() ? AdminFilter : UserFilter\n    return User.filter(request.qs(), filter).exec()\n  } \n}\n```\n\n### Filtering relations\n\nFor filtering relations of model may be use `.query().filter()` or scope `filtration`, example:\n\n```ts\nimport type { HttpContext } from '@adonisjs/core/http'\nimport User from '#models/user'\n\nexport default class UserPostsController {\n  /**\n   * Get a list posts of user\n   * GET /users/:user_id/posts\n   */\n  async index({ params, request }: HttpContext): Promise\u003cPost[]\u003e {\n    const user: User = await User.findOrFail(params.user_id)\n    \n    return user.related('posts').query()\n      .apply(scopes =\u003e scopes.filtration(request.qs()))\n      .exec()\n\n    // or\n\n    return user.related('posts').query().filter(request.qs()).exec()\n  }\n}\n```\n\nDocumentation by [Query Scopes](https://lucid.adonisjs.com/docs/model-query-scopes)\n\n**Note:** The relation model must be `Filterable` and `$filter` must be defined in it\n\n[npm-image]: https://img.shields.io/npm/v/adonis-lucid-filter?logo=npm\u0026style=for-the-badge\n[npm-url]: https://www.npmjs.com/package/adonis-lucid-filter\n\n[license-image]: https://img.shields.io/npm/l/adonis-lucid-filter?style=for-the-badge\u0026color=blueviolet\n[license-url]: https://github.com/lookinlab/adonis-lucid-filter/blob/develop/LICENSE.md\n\n[typescript-image]: https://img.shields.io/npm/types/adonis-lucid-filter?color=294E80\u0026label=%20\u0026logo=typescript\u0026style=for-the-badge\n[typescript-url]: https://github.com/lookinlab\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flookinlab%2Fadonis-lucid-filter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flookinlab%2Fadonis-lucid-filter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flookinlab%2Fadonis-lucid-filter/lists"}