Skip to content

Commit e1afa2a

Browse files
docs (#130)
Add documentation website.
1 parent 9218349 commit e1afa2a

17 files changed

+11624
-0
lines changed

docs/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
.nuxt
3+
dist
+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
---
2+
title: CRUD Operations
3+
description: 'CRUD Operations.'
4+
position: 8
5+
category: API
6+
---
7+
8+
## `save`
9+
- Returns: `Model | { data: Model }`
10+
11+
Save or update a model in the database, then return the instance.
12+
13+
### create
14+
15+
<code-group>
16+
<code-block Label="Query 1" active>
17+
18+
```js
19+
const model = new Model({ foo: 'bar' })
20+
21+
model.save()
22+
```
23+
24+
</code-block>
25+
<code-block Label="Query 2">
26+
27+
```js
28+
const model = new Model()
29+
30+
model.foo = 'bar'
31+
32+
model.save()
33+
```
34+
35+
</code-block>
36+
<code-block Label="Request">
37+
38+
```http request
39+
POST /resource
40+
```
41+
42+
</code-block>
43+
</code-group>
44+
45+
### update
46+
47+
<code-group>
48+
<code-block Label="Query" active>
49+
50+
```js
51+
const model = await Model.find(1)
52+
53+
model.foo = 'bar'
54+
55+
model.save()
56+
```
57+
58+
</code-block>
59+
<code-block Label="Request">
60+
61+
```http request
62+
PUT /resource/1
63+
```
64+
65+
</code-block>
66+
</code-group>
67+
68+
69+
## `delete`
70+
71+
Delete the model from the database.
72+
73+
<code-group>
74+
<code-block Label="Query" active>
75+
76+
```js
77+
const model = await Model.find(1)
78+
79+
model.delete()
80+
```
81+
82+
</code-block>
83+
<code-block Label="Find Request">
84+
85+
```http request
86+
GET /resource/1
87+
```
88+
89+
</code-block>
90+
<code-block Label="Delete Request">
91+
92+
```http request
93+
DELETE /resource/1
94+
```
95+
96+
</code-block>
97+
</code-group>

docs/content/en/api/model-options.md

+160
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
---
2+
title: Model Options
3+
description: 'Model Options.'
4+
position: 6
5+
category: API
6+
---
7+
8+
## Global Options
9+
10+
It's recommended to define the global options in your [Base Model](/configuration#creating-a-base-model),
11+
in order to abstract configuration from your models.
12+
13+
### `$http`
14+
- Returns: `HTTP Client Instance`
15+
16+
Instance of the HTTP client which is used to make requests.
17+
18+
See [Installation](/installation)
19+
20+
### `baseURL`
21+
- Returns: `string`
22+
23+
Base URL which is used and prepended to make requests.
24+
25+
See [Configuration](/configuration#creating-a-base-model)
26+
27+
```js
28+
baseURL() {
29+
return 'http://my-api.com'
30+
}
31+
```
32+
33+
### `request`
34+
- Arguments: `(config)`
35+
- Returns: `HTTP Client Request`
36+
37+
Request method which is used to make requests.
38+
39+
See [Configuration](/configuration#creating-a-base-model)
40+
41+
```js
42+
request(config) {
43+
return this.$http.request(config)
44+
}
45+
```
46+
47+
### `parameterNames`
48+
- Returns: `object`
49+
50+
This method can be overridden in the model to customize the name of the query parameters.
51+
52+
See [Configuration](/configuration#customizing-query-parameters)
53+
54+
```js
55+
parameterNames() {
56+
return {
57+
include: 'include',
58+
filter: 'filter',
59+
sort: 'sort',
60+
fields: 'fields',
61+
append: 'append',
62+
page: 'page',
63+
limit: 'limit'
64+
}
65+
}
66+
```
67+
68+
#### `include`
69+
- Default: `include`
70+
- Returns: `string`
71+
72+
#### `filter`
73+
- Default: `filter`
74+
- Returns: `string`
75+
76+
#### `sort`
77+
- Default: `sort`
78+
- Returns: `string`
79+
80+
#### `fields`
81+
- Default: `fields`
82+
- Returns: `string`
83+
84+
#### `append`
85+
- Default: `append`
86+
- Returns: `string`
87+
88+
#### `page`
89+
- Default: `page`
90+
- Returns: `string`
91+
92+
#### `limit`
93+
- Default: `limit`
94+
- Returns: `string`
95+
96+
## Model Options
97+
98+
These are model-related options.
99+
100+
### `resource`
101+
- Returns: `string`
102+
103+
Resource route of the model which is used to build the query.
104+
105+
See [Configuration](/configuration#creating-the-domain-models)
106+
107+
```js
108+
resource() {
109+
return 'resource'
110+
}
111+
```
112+
113+
### `primaryKey`
114+
- Default: `id`
115+
- Returns: `string`
116+
117+
Primary key of the model which is used to build the query.
118+
119+
See [Configuration](/configuration#changing-the-primary-key)
120+
121+
```js
122+
primaryKey() {
123+
return 'id'
124+
}
125+
```
126+
127+
### `relations`
128+
- Returns: `object`
129+
130+
This method can be implemented in the model to apply model instances to eager loaded relationships.
131+
It works for collections too.
132+
133+
It must return an object, which the key is the property of the relationship, and the value is the
134+
model instance.
135+
136+
See [Configuration](/configuration#eager-loaded-relationships)
137+
138+
```js
139+
relations() {
140+
return {
141+
comments: Comment
142+
}
143+
}
144+
```
145+
146+
### `hasMany`
147+
- Arguments: `(model)`
148+
- Returns: `Model`
149+
150+
This method can be used to lazy load relationships of a model and apply model instances to them.
151+
152+
It must receive a model instance as argument.
153+
154+
See [Configuration](/configuration#lazy-loading-relationships)
155+
156+
```js
157+
comments() {
158+
return this.hasMany(Comment)
159+
}
160+
```

0 commit comments

Comments
 (0)