@codenameryuu/adonis-lucid-filter 2.4.0 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -41
- package/package.json +8 -11
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @codenameryuu/adonis-lucid-filter
|
|
2
2
|
|
|
3
|
-
> Works with
|
|
3
|
+
> Works with Adonis JS V7
|
|
4
4
|
|
|
5
5
|
[![npm-image]][npm-url] [![license-image]][license-url] [![typescript-image]][typescript-url]
|
|
6
6
|
|
|
@@ -8,26 +8,11 @@ This addon adds the functionality to filter Lucid Models
|
|
|
8
8
|
|
|
9
9
|
> Inspired by [EloquentFilter](https://github.com/Tucker-Eric/EloquentFilter)
|
|
10
10
|
|
|
11
|
-
## Versions
|
|
12
|
-
|
|
13
|
-
> **Note**: Check before install :point_down:
|
|
14
|
-
|
|
15
|
-
| adonis-lucid-filter | @adonisjs/lucid |
|
|
16
|
-
| ------------------------------------ | --------------- |
|
|
17
|
-
| ^5.\*.\* | ^20.\*.\* |
|
|
18
|
-
| ^4.\*.\* | <=18.\*.\* |
|
|
19
|
-
| ^3.\*.\* (`@filterable()` decorator) | ^15.\*.\* |
|
|
20
|
-
| ^2.\*.\* | 14.\*.\* |
|
|
21
|
-
|
|
22
|
-
- Docs [for **Adonis v5**](https://github.com/lookinlab/adonis-lucid-filter/tree/v4)
|
|
23
|
-
- Docs [for **Adonis v4**](https://github.com/lookinlab/adonis-lucid-filter/tree/v1)
|
|
24
|
-
- Docs [for `@filterable()` decorator](https://github.com/lookinlab/adonis-lucid-filter/tree/v3)
|
|
25
|
-
|
|
26
11
|
## Introduction
|
|
27
12
|
|
|
28
13
|
Example, we want to return a list of users filtered by multiple parameters. When we navigate to:
|
|
29
14
|
|
|
30
|
-
`/users?name=Tony&lastName=&companyId=2&industry=5`
|
|
15
|
+
`/users?name=Tony&lastName=&companyId=2&industry=5`
|
|
31
16
|
|
|
32
17
|
`request.all()` or `request.qs()` will return:
|
|
33
18
|
|
|
@@ -80,43 +65,36 @@ export default class UsersController {
|
|
|
80
65
|
|
|
81
66
|
## Installation
|
|
82
67
|
|
|
83
|
-
|
|
68
|
+
* Install the package
|
|
84
69
|
|
|
85
70
|
```bash
|
|
86
|
-
|
|
87
|
-
npm i adonis-lucid-filter
|
|
88
|
-
|
|
89
|
-
# yarn
|
|
90
|
-
yarn add adonis-lucid-filter
|
|
91
|
-
|
|
92
|
-
# pnpm
|
|
93
|
-
pnpm add adonis-lucid-filter
|
|
71
|
+
yarn add @codenameryuu/adonis-lucid-filter
|
|
94
72
|
```
|
|
95
73
|
|
|
96
|
-
|
|
74
|
+
* Configure the package
|
|
97
75
|
|
|
98
76
|
```bash
|
|
99
|
-
node ace configure adonis-lucid-filter
|
|
77
|
+
node ace configure @codenameryuu/adonis-lucid-filter
|
|
100
78
|
```
|
|
101
79
|
|
|
102
80
|
## Usage
|
|
103
81
|
|
|
104
|
-
|
|
82
|
+
* Register the provider and commands inside `adonisrc.ts` file.
|
|
105
83
|
|
|
106
84
|
```ts
|
|
107
85
|
providers: [
|
|
108
86
|
// ...
|
|
109
|
-
() => import('adonis-lucid-filter/provider'),
|
|
87
|
+
() => import('@codenameryuu/adonis-lucid-filter/provider'),
|
|
110
88
|
],
|
|
111
89
|
commands: [
|
|
112
90
|
// ...
|
|
113
|
-
() => import('adonis-lucid-filter/commands')
|
|
91
|
+
() => import('@codenameryuu/adonis-lucid-filter/commands')
|
|
114
92
|
]
|
|
115
93
|
```
|
|
116
94
|
|
|
117
95
|
### Generating The Filter
|
|
118
96
|
|
|
119
|
-
> Only available if you have added
|
|
97
|
+
> Only available if you have added `@codenameryuu/adonis-lucid-filter/commands` in `commands` array in your `adonisrc.ts'
|
|
120
98
|
|
|
121
99
|
You can create a model filter with the following ace command:
|
|
122
100
|
|
|
@@ -130,13 +108,13 @@ Where `user` is the Lucid Model you are creating the filter for. This will creat
|
|
|
130
108
|
|
|
131
109
|
Define the filter logic based on the camel cased input key passed to the `filter()` method.
|
|
132
110
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
111
|
+
* Empty strings are ignored
|
|
112
|
+
* `setup()` will be called regardless of input
|
|
113
|
+
* `_id` is dropped from the end of the input to define the method so filtering `user_id` would use the `user()` method
|
|
114
|
+
* Input without a corresponding filter method are ignored
|
|
115
|
+
* The value of the key is injected into the method
|
|
116
|
+
* All values are accessible through the `this.$input` a property
|
|
117
|
+
* All QueryBuilder methods are accessible in `this.$query` object in the model filter class.
|
|
140
118
|
|
|
141
119
|
To define methods for the following input:
|
|
142
120
|
|
|
@@ -276,7 +254,7 @@ export default class UsersController {
|
|
|
276
254
|
|
|
277
255
|
### Filtering relations
|
|
278
256
|
|
|
279
|
-
For filtering relations of model may be use `.query().filter()` or scope `filtration
|
|
257
|
+
For filtering relations of model may be use `.query().filter()` or scope `filtration` , example:
|
|
280
258
|
|
|
281
259
|
```ts
|
|
282
260
|
import type { HttpContext } from '@adonisjs/core/http'
|
package/package.json
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codenameryuu/adonis-lucid-filter",
|
|
3
3
|
"description": "Addon for filtering Adonis JS 7 Lucid ORM",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.5.0",
|
|
5
|
+
"author": "codenameryuu",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://github.com/codenameryuu/adonis-lucid-filter#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/codenameryuu/adonis-lucid-filter.git"
|
|
11
|
+
},
|
|
5
12
|
"engines": {
|
|
6
13
|
"node": ">=24.0.0"
|
|
7
14
|
},
|
|
@@ -74,16 +81,6 @@
|
|
|
74
81
|
"@adonisjs/core": "^7.0.0",
|
|
75
82
|
"@adonisjs/lucid": "^22.0.0"
|
|
76
83
|
},
|
|
77
|
-
"author": "LookinGit",
|
|
78
|
-
"license": "MIT",
|
|
79
|
-
"homepage": "https://github.com/lookinlab/adonis-lucid-filter#readme",
|
|
80
|
-
"repository": {
|
|
81
|
-
"type": "git",
|
|
82
|
-
"url": "git+ssh://git@github.com/lookinlab/adonis-lucid-filter.git"
|
|
83
|
-
},
|
|
84
|
-
"bugs": {
|
|
85
|
-
"url": "https://github.com/lookinlab/adonis-lucid-filter/issues"
|
|
86
|
-
},
|
|
87
84
|
"keywords": [
|
|
88
85
|
"adonisjs",
|
|
89
86
|
"adonisjs-filter",
|