Skip to content

Commit 448d6b7

Browse files
Merge pull request #244 from robsontenorio/dev
Release v1.10.0
2 parents 2d1d887 + 8a1230c commit 448d6b7

15 files changed

+2106
-2249
lines changed

.github/FUNDING.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
2+
github: [JoaoPedroAS51]

.github/workflows/test-and-release.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ jobs:
5353
strategy:
5454
matrix:
5555
os: [ ubuntu-latest ]
56-
node-version: [ 12.x, 14.x ]
56+
node-version: [ 14.x, 16.x, 18.x ]
5757
fail-fast: true
5858

5959
steps:
6060
- name: Checkout
6161
uses: actions/checkout@v2
6262

6363
- name: Use Node.js ${{ matrix.node-version }}
64-
uses: actions/setup-node@v2-beta
64+
uses: actions/setup-node@v2
6565
with:
6666
node-version: ${{ matrix.node-version }}
6767

@@ -140,15 +140,15 @@ jobs:
140140
strategy:
141141
matrix:
142142
os: [ ubuntu-latest ]
143-
node-version: [ 12.x ]
143+
node-version: [ 16.x ]
144144
fail-fast: true
145145

146146
steps:
147147
- name: Checkout
148148
uses: actions/checkout@v2
149149

150150
- name: Use Node.js ${{ matrix.node-version }}
151-
uses: actions/setup-node@v2-beta
151+
uses: actions/setup-node@v2
152152
with:
153153
node-version: ${{ matrix.node-version }}
154154

docs/content/en/api/query-builder-methods.md

+30
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ await Model.where('status', 'active')
8080
await Model.where(['user', 'status'], 'active')
8181
```
8282

83+
#### Object
84+
85+
<alert type="success">Available in version >= v1.10.0</alert>
86+
87+
```js
88+
await Model.where({ user: { status: 'active' } })
89+
```
90+
8391
## `whereIn`
8492
- Arguments: `(field, array)`
8593
- Returns: `self`
@@ -98,6 +106,14 @@ await Model.whereIn('id', [1, 2, 3])
98106
await Model.whereIn(['user', 'id'], [1, 2, 3])
99107
```
100108

109+
#### Object
110+
111+
<alert type="success">Available in version >= v1.10.0</alert>
112+
113+
```js
114+
await Model.where({ user: { id: [1, 2, 3] } })
115+
```
116+
101117
## `orderBy`
102118
- Arguments: `(...args)`
103119
- Returns: `self`
@@ -162,6 +178,20 @@ Add custom parameters to the query.
162178
</code-block>
163179
</code-group>
164180

181+
## `when`
182+
<alert type="success">Available in version >= v1.10.0</alert>
183+
184+
- Arguments: `(value, callback)`
185+
- Returns: `self`
186+
187+
Add a conditional clause to the query.
188+
189+
```js
190+
const search = 'foo'
191+
192+
await Model.when(search, (query, value) => query.where('search', value))
193+
```
194+
165195
## `custom`
166196
- Arguments: `(...args)`
167197
- Returns: `self`

docs/content/en/building-the-query.md

+84-1
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,34 @@ So we can filter our **Posts** to only get results where `status` of `user` is `
276276
</code-block>
277277
</code-group>
278278

279+
#### Using an Object
280+
281+
<alert type="success">Available in version >= v1.10.0</alert>
282+
283+
Now is also possible to pass an object.
284+
285+
<code-group>
286+
<code-block label="Query" active>
287+
288+
```js
289+
const posts = await Post.where({
290+
status: 'published',
291+
user: {
292+
status: 'active'
293+
}
294+
}).get()
295+
```
296+
297+
</code-block>
298+
<code-block label="Request">
299+
300+
```http request
301+
GET /posts?filter[status]=published&filter[user][status]=active
302+
```
303+
304+
</code-block>
305+
</code-group>
306+
279307
### Evaluating Multiple Values
280308

281309
See the [API reference](/api/query-builder-methods#wherein)
@@ -332,6 +360,34 @@ So we can filter our **Posts** to only get results where `status` of `user` is `
332360
</code-block>
333361
</code-group>
334362

363+
#### Using an Object
364+
365+
<alert type="success">Available in version >= v1.10.0</alert>
366+
367+
Now is also possible to pass an object.
368+
369+
<code-group>
370+
<code-block label="Query" active>
371+
372+
```js
373+
const posts = await Post.where({
374+
status: ['published', 'archived'],
375+
user: {
376+
status: ['active', 'inactive']
377+
}
378+
}).get()
379+
```
380+
381+
</code-block>
382+
<code-block label="Request">
383+
384+
```http request
385+
GET /posts?filter[status]=published,archived&filter[user][status]=active,inactive
386+
```
387+
388+
</code-block>
389+
</code-group>
390+
335391
## Sorting
336392

337393
See the [API reference](/api/query-builder-methods#orderby)
@@ -597,11 +653,38 @@ Let's say we are at page 1, and we want 20 **Posts** per page:
597653
</code-block>
598654
</code-group>
599655

656+
## Conditional
657+
658+
<alert type="success">Available in version >= v1.10.0</alert>
659+
660+
We may need to add a clause based on a condition, and we can do so by using the `when` method.
661+
The first argument is the flag, and the second argument is the callback with the clause we want.
662+
663+
664+
<code-group>
665+
<code-block label="Query" active>
666+
667+
```js
668+
const search = 'foo'
669+
const posts = await Post.when(search, (query, value) => query.where('title', value)).get()
670+
```
671+
672+
</code-block>
673+
<code-block label="Request">
674+
675+
```http request
676+
GET /posts?filter[title]=foo
677+
```
678+
679+
</code-block>
680+
</code-group>
681+
682+
600683
## Applying Custom Parameters
601684

602685
See the [API reference](/api/query-builder-methods#params)
603686

604-
We may need to use parameters that are not provided by [vue-api-query](https://github.com/robsontenorio/vue-api-query),
687+
We may also need to use parameters that are not provided by [vue-api-query](https://github.com/robsontenorio/vue-api-query),
605688
and that's when the `params` method comes in to help.
606689

607690
The argument is an object of the parameters to add to the query.

docs/content/en/configuration.md

+38
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,44 @@ export default class User extends Model {
8383
}
8484
```
8585

86+
### Typescript
87+
88+
<alert type="success">Available in version >= v1.9.0</alert>
89+
90+
If we are working on a Typescript project, we can infer the types of the fields, so we have intellisense.
91+
92+
#### Directly in Model
93+
```ts{}[~/models/User.ts]
94+
import Model from './Model'
95+
96+
export default class User extends Model {
97+
firstName: string
98+
lastName: string
99+
age: number
100+
101+
...
102+
}
103+
```
104+
105+
#### Using an Interface
106+
```ts{}[~/models/User.ts]
107+
import Model from './Model'
108+
109+
interface User {
110+
firstName: string
111+
lastName: string
112+
age: number
113+
}
114+
115+
class User extends Model {
116+
...
117+
}
118+
119+
export default User
120+
```
121+
122+
<alert type="info">You can use `!` operator to make non-null assertion.</alert>
123+
86124
## Changing the Primary Key
87125

88126
<alert type="info">By default, the `primaryKey` is set to `id`.</alert>

docs/content/en/index.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ category: Getting Started
77

88
Elegant and simple way to build requests for REST API.
99

10-
This package helps you quickly to build requests for REST API. Move your logic and backend requests to dedicated classes. Keep your code clean and elegant.
10+
This package helps you quickly to build requests for REST API. Move your logic and backend requests to dedicated
11+
classes. Keep your code clean and elegant.
1112

13+
🔥 If you use Laravel, this package matches perfectly
14+
with [spatie/laravel-query-builder](https://github.com/spatie/laravel-query-builder).
1215

13-
🔥 If you use Laravel, this package matches perfectly with [spatie/laravel-query-builder](https://github.com/spatie/laravel-query-builder).
16+
### Liked our work? Consider buying us a coffee ☕
17+
18+
* [@JoaoPedroAS51](https://github.com/sponsors/JoaoPedroAS51)

0 commit comments

Comments
 (0)