Skip to content

Commit

Permalink
docs (#130)
Browse files Browse the repository at this point in the history
Add documentation website.
  • Loading branch information
JoaoPedroAS51 authored Oct 31, 2020
1 parent 9218349 commit e1afa2a
Show file tree
Hide file tree
Showing 17 changed files with 11,624 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
.nuxt
dist
97 changes: 97 additions & 0 deletions docs/content/en/api/crud-operations.md
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>
160 changes: 160 additions & 0 deletions docs/content/en/api/model-options.md
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)
}
```
Loading

0 comments on commit e1afa2a

Please sign in to comment.