Skip to content

Commit

Permalink
Merge pull request #244 from robsontenorio/dev
Browse files Browse the repository at this point in the history
Release v1.10.0
  • Loading branch information
JoaoPedroAS51 authored Jul 5, 2022
2 parents 2d1d887 + 8a1230c commit 448d6b7
Show file tree
Hide file tree
Showing 15 changed files with 2,106 additions and 2,249 deletions.
2 changes: 2 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
github: [JoaoPedroAS51]
8 changes: 4 additions & 4 deletions .github/workflows/test-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ jobs:
strategy:
matrix:
os: [ ubuntu-latest ]
node-version: [ 12.x, 14.x ]
node-version: [ 14.x, 16.x, 18.x ]
fail-fast: true

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2-beta
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}

Expand Down Expand Up @@ -140,15 +140,15 @@ jobs:
strategy:
matrix:
os: [ ubuntu-latest ]
node-version: [ 12.x ]
node-version: [ 16.x ]
fail-fast: true

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2-beta
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}

Expand Down
30 changes: 30 additions & 0 deletions docs/content/en/api/query-builder-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ await Model.where('status', 'active')
await Model.where(['user', 'status'], 'active')
```

#### Object

<alert type="success">Available in version >= v1.10.0</alert>

```js
await Model.where({ user: { status: 'active' } })
```

## `whereIn`
- Arguments: `(field, array)`
- Returns: `self`
Expand All @@ -98,6 +106,14 @@ await Model.whereIn('id', [1, 2, 3])
await Model.whereIn(['user', 'id'], [1, 2, 3])
```

#### Object

<alert type="success">Available in version >= v1.10.0</alert>

```js
await Model.where({ user: { id: [1, 2, 3] } })
```

## `orderBy`
- Arguments: `(...args)`
- Returns: `self`
Expand Down Expand Up @@ -162,6 +178,20 @@ Add custom parameters to the query.
</code-block>
</code-group>

## `when`
<alert type="success">Available in version >= v1.10.0</alert>

- Arguments: `(value, callback)`
- Returns: `self`

Add a conditional clause to the query.

```js
const search = 'foo'

await Model.when(search, (query, value) => query.where('search', value))
```

## `custom`
- Arguments: `(...args)`
- Returns: `self`
Expand Down
85 changes: 84 additions & 1 deletion docs/content/en/building-the-query.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,34 @@ So we can filter our **Posts** to only get results where `status` of `user` is `
</code-block>
</code-group>

#### Using an Object

<alert type="success">Available in version >= v1.10.0</alert>

Now is also possible to pass an object.

<code-group>
<code-block label="Query" active>

```js
const posts = await Post.where({
status: 'published',
user: {
status: 'active'
}
}).get()
```

</code-block>
<code-block label="Request">

```http request
GET /posts?filter[status]=published&filter[user][status]=active
```

</code-block>
</code-group>

### Evaluating Multiple Values

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

#### Using an Object

<alert type="success">Available in version >= v1.10.0</alert>

Now is also possible to pass an object.

<code-group>
<code-block label="Query" active>

```js
const posts = await Post.where({
status: ['published', 'archived'],
user: {
status: ['active', 'inactive']
}
}).get()
```

</code-block>
<code-block label="Request">

```http request
GET /posts?filter[status]=published,archived&filter[user][status]=active,inactive
```

</code-block>
</code-group>

## Sorting

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

## Conditional

<alert type="success">Available in version >= v1.10.0</alert>

We may need to add a clause based on a condition, and we can do so by using the `when` method.
The first argument is the flag, and the second argument is the callback with the clause we want.


<code-group>
<code-block label="Query" active>

```js
const search = 'foo'
const posts = await Post.when(search, (query, value) => query.where('title', value)).get()
```

</code-block>
<code-block label="Request">

```http request
GET /posts?filter[title]=foo
```

</code-block>
</code-group>


## Applying Custom Parameters

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

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

The argument is an object of the parameters to add to the query.
Expand Down
38 changes: 38 additions & 0 deletions docs/content/en/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,44 @@ export default class User extends Model {
}
```

### Typescript

<alert type="success">Available in version >= v1.9.0</alert>

If we are working on a Typescript project, we can infer the types of the fields, so we have intellisense.

#### Directly in Model
```ts{}[~/models/User.ts]
import Model from './Model'
export default class User extends Model {
firstName: string
lastName: string
age: number
...
}
```

#### Using an Interface
```ts{}[~/models/User.ts]
import Model from './Model'
interface User {
firstName: string
lastName: string
age: number
}
class User extends Model {
...
}
export default User
```

<alert type="info">You can use `!` operator to make non-null assertion.</alert>

## Changing the Primary Key

<alert type="info">By default, the `primaryKey` is set to `id`.</alert>
Expand Down
9 changes: 7 additions & 2 deletions docs/content/en/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ category: Getting Started

Elegant and simple way to build requests for REST API.

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.
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.

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

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

* [@JoaoPedroAS51](https://github.com/sponsors/JoaoPedroAS51)
Loading

0 comments on commit 448d6b7

Please sign in to comment.