-
-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
17 changed files
with
11,624 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
.nuxt | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
--- | ||
title: CRUD Operations | ||
description: 'CRUD Operations.' | ||
position: 8 | ||
category: API | ||
--- | ||
|
||
## `save` | ||
- Returns: `Model | { data: Model }` | ||
|
||
Save or update a model in the database, then return the instance. | ||
|
||
### create | ||
|
||
<code-group> | ||
<code-block Label="Query 1" active> | ||
|
||
```js | ||
const model = new Model({ foo: 'bar' }) | ||
|
||
model.save() | ||
``` | ||
|
||
</code-block> | ||
<code-block Label="Query 2"> | ||
|
||
```js | ||
const model = new Model() | ||
|
||
model.foo = 'bar' | ||
|
||
model.save() | ||
``` | ||
|
||
</code-block> | ||
<code-block Label="Request"> | ||
|
||
```http request | ||
POST /resource | ||
``` | ||
|
||
</code-block> | ||
</code-group> | ||
|
||
### update | ||
|
||
<code-group> | ||
<code-block Label="Query" active> | ||
|
||
```js | ||
const model = await Model.find(1) | ||
|
||
model.foo = 'bar' | ||
|
||
model.save() | ||
``` | ||
|
||
</code-block> | ||
<code-block Label="Request"> | ||
|
||
```http request | ||
PUT /resource/1 | ||
``` | ||
|
||
</code-block> | ||
</code-group> | ||
|
||
|
||
## `delete` | ||
|
||
Delete the model from the database. | ||
|
||
<code-group> | ||
<code-block Label="Query" active> | ||
|
||
```js | ||
const model = await Model.find(1) | ||
|
||
model.delete() | ||
``` | ||
|
||
</code-block> | ||
<code-block Label="Find Request"> | ||
|
||
```http request | ||
GET /resource/1 | ||
``` | ||
|
||
</code-block> | ||
<code-block Label="Delete Request"> | ||
|
||
```http request | ||
DELETE /resource/1 | ||
``` | ||
|
||
</code-block> | ||
</code-group> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
--- | ||
title: Model Options | ||
description: 'Model Options.' | ||
position: 6 | ||
category: API | ||
--- | ||
|
||
## Global Options | ||
|
||
It's recommended to define the global options in your [Base Model](/configuration#creating-a-base-model), | ||
in order to abstract configuration from your models. | ||
|
||
### `$http` | ||
- Returns: `HTTP Client Instance` | ||
|
||
Instance of the HTTP client which is used to make requests. | ||
|
||
See [Installation](/installation) | ||
|
||
### `baseURL` | ||
- Returns: `string` | ||
|
||
Base URL which is used and prepended to make requests. | ||
|
||
See [Configuration](/configuration#creating-a-base-model) | ||
|
||
```js | ||
baseURL() { | ||
return 'http://my-api.com' | ||
} | ||
``` | ||
|
||
### `request` | ||
- Arguments: `(config)` | ||
- Returns: `HTTP Client Request` | ||
|
||
Request method which is used to make requests. | ||
|
||
See [Configuration](/configuration#creating-a-base-model) | ||
|
||
```js | ||
request(config) { | ||
return this.$http.request(config) | ||
} | ||
``` | ||
|
||
### `parameterNames` | ||
- Returns: `object` | ||
|
||
This method can be overridden in the model to customize the name of the query parameters. | ||
|
||
See [Configuration](/configuration#customizing-query-parameters) | ||
|
||
```js | ||
parameterNames() { | ||
return { | ||
include: 'include', | ||
filter: 'filter', | ||
sort: 'sort', | ||
fields: 'fields', | ||
append: 'append', | ||
page: 'page', | ||
limit: 'limit' | ||
} | ||
} | ||
``` | ||
|
||
#### `include` | ||
- Default: `include` | ||
- Returns: `string` | ||
|
||
#### `filter` | ||
- Default: `filter` | ||
- Returns: `string` | ||
|
||
#### `sort` | ||
- Default: `sort` | ||
- Returns: `string` | ||
|
||
#### `fields` | ||
- Default: `fields` | ||
- Returns: `string` | ||
|
||
#### `append` | ||
- Default: `append` | ||
- Returns: `string` | ||
|
||
#### `page` | ||
- Default: `page` | ||
- Returns: `string` | ||
|
||
#### `limit` | ||
- Default: `limit` | ||
- Returns: `string` | ||
|
||
## Model Options | ||
|
||
These are model-related options. | ||
|
||
### `resource` | ||
- Returns: `string` | ||
|
||
Resource route of the model which is used to build the query. | ||
|
||
See [Configuration](/configuration#creating-the-domain-models) | ||
|
||
```js | ||
resource() { | ||
return 'resource' | ||
} | ||
``` | ||
|
||
### `primaryKey` | ||
- Default: `id` | ||
- Returns: `string` | ||
|
||
Primary key of the model which is used to build the query. | ||
|
||
See [Configuration](/configuration#changing-the-primary-key) | ||
|
||
```js | ||
primaryKey() { | ||
return 'id' | ||
} | ||
``` | ||
|
||
### `relations` | ||
- Returns: `object` | ||
|
||
This method can be implemented in the model to apply model instances to eager loaded relationships. | ||
It works for collections too. | ||
|
||
It must return an object, which the key is the property of the relationship, and the value is the | ||
model instance. | ||
|
||
See [Configuration](/configuration#eager-loaded-relationships) | ||
|
||
```js | ||
relations() { | ||
return { | ||
comments: Comment | ||
} | ||
} | ||
``` | ||
|
||
### `hasMany` | ||
- Arguments: `(model)` | ||
- Returns: `Model` | ||
|
||
This method can be used to lazy load relationships of a model and apply model instances to them. | ||
|
||
It must receive a model instance as argument. | ||
|
||
See [Configuration](/configuration#lazy-loading-relationships) | ||
|
||
```js | ||
comments() { | ||
return this.hasMany(Comment) | ||
} | ||
``` |
Oops, something went wrong.