Skip to content

Commit

Permalink
Upgrade v1.9.0 (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
hwbrzzl authored Feb 13, 2023
1 parent d85c3df commit f73facc
Show file tree
Hide file tree
Showing 22 changed files with 520 additions and 66 deletions.
32 changes: 6 additions & 26 deletions .vuepress/config/sidebar/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,16 @@ export function getEnSidebar(): SidebarConfigArray {
text: "Upgrade Guide",
children: [
{
text: "Upgrading To v1.8 From v1.7",
link: "/upgrade/v1.8",
},
{
text: "Upgrading To v1.7 From v1.6",
link: "/upgrade/v1.7",
},
{
text: "Upgrading To v1.6 From v1.5",
link: "/upgrade/v1.6",
},
{
text: "Upgrading To v1.5 From v1.4",
link: "/upgrade/v1.5",
},
{
text: "Upgrading To v1.4 From v1.3",
link: "/upgrade/v1.4",
text: "Upgrading To v1.9 From v1.8",
link: "/upgrade/v1.9",
},
{
text: "Upgrading To v1.3 From v1.2",
link: "/upgrade/v1.3",
},
{
text: "Upgrading To v1.2 From v1.1",
link: "/upgrade/v1.2",
text: "Upgrading To v1.8 From v1.7",
link: "/upgrade/v1.8",
},
{
text: "Upgrading To v1.1 From v1.0",
link: "/upgrade/v1.1",
text: "History Upgrade",
link: "/upgrade/history",
},
],
},
Expand Down
34 changes: 7 additions & 27 deletions .vuepress/config/sidebar/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,16 @@ export function getZhSidebar(): SidebarConfigArray {
text: "升级指南",
children: [
{
text: "从 v1.7 升级到 v1.8",
link: "/zh/upgrade/v1.8",
},
{
text: "从 v1.6 升级到 v1.7",
link: "/zh/upgrade/v1.7",
},
{
text: "从 v1.5 升级到 v1.6",
link: "/zh/upgrade/v1.6",
},
{
text: "从 v1.4 升级到 v1.5",
link: "/zh/upgrade/v1.5",
},
{
text: "从 v1.3 升级到 v1.4",
link: "/zh/upgrade/v1.4",
text: "从 v1.8 升级到 v1.9",
link: "/zh/upgrade/v1.9",
},
{
text: "从 v1.2 升级到 v1.3",
link: "/zh/upgrade/v1.3",
},
{
text: "从 v1.1 升级到 v1.2",
link: "/zh/upgrade/v1.2",
text: "从 v1.7 升级到 v1.8",
link: "/zh/upgrade/v1.8",
},
{
text: "从 v1.0 升级到 v1.1",
link: "/zh/upgrade/v1.1",
text: "历史版本升级",
link: "/zh/upgrade/history",
},
],
},
Expand Down Expand Up @@ -131,7 +111,7 @@ export function getZhSidebar(): SidebarConfigArray {
},
{
text: "用户授权",
link: "/digging-deeper/authorization",
link: "/zh/digging-deeper/authorization",
},
{
text: "缓存系统",
Expand Down
64 changes: 62 additions & 2 deletions ORM/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,66 @@ Before starting, please configure the database in the `.env` file and confirm th

The configuration of databases is in the `config/database.go` file. You can configure all database connections in this file and specify the default database connection. Most of configuration in this file is based on the project's environment variables, and provides examples of database configurations supported by Goravel.

### Read & Write Connections

Sometimes you may wish to use one database connection for `SELECT` statements, and another for `INSERT`, `UPDATE`, and `DELETE` statements. Goravel makes this a breeze.

To see how read / write connections should be configured, let's look at this example:

```
import "github.com/goravel/framework/contracts/database"
// config/database.go
"connections": map[string]any{
"mysql": map[string]any{
"driver": "mysql",
"read": []database.Config{
{Host: "192.168.1.1", Port: 3306, Database: "forge", Username: "root", Password: "123123"},
},
"write": []database.Config{
{Host: "192.168.1.2", Port: 3306, Database: "forge", Username: "root", Password: "123123"},
},
"host": config.Env("DB_HOST", "127.0.0.1"),
"port": config.Env("DB_PORT", 3306),
"database": config.Env("DB_DATABASE", "forge"),
"username": config.Env("DB_USERNAME", ""),
"password": config.Env("DB_PASSWORD", ""),
"charset": "utf8mb4",
"loc": "Local",
},
}
```

Two keys have been added to the configuration array: `read` and `write`, `192.168.1.1` will be used as the host for the "read" connection, while `192.168.1.2` will be used for the "write" connection. The database prefix, character set, and all other options in the main `mysql` array will be shared across both connections. When multiple values exist in the `host` configuration array, a database host will be randomly chosen for each request.

### Connection Pool

You can configure connection pool in the configuration file, reasonable configuration of connection pool parameters can greatly improve concurrency performance:

| Key | Action |
| ----------- | -------------- |
| pool.max_idle_conns | Max idle connections |
| pool.max_open_conns | Max open connections |
| pool.conn_max_idletime | Connections max idle time |
| pool.conn_max_lifetime | Connections max lifetime |

## Model Definition

You can create a custom model based on the model file `app/models/user.go` that comes with the framework. In the `app/models/user.go` file, `struct` has nested two frameworks, `orm.Model` and `orm.SoftDeletes`, they define `id, created_at, updated_at` and `deleted_at` respectively, `orm.SoftDeletes` means that soft deletion is enabled for the model.

## Model Convention
### Model Convention

1. The model is named with a big hump;
2. Use the plural form of the model "snake naming" as the table name;

For example, the model name is `UserOrder`, the table name is `user_orders`.

### Create Model

```
go run . artisan make:model User
```

## facades.Orm available functions

| Name | Action |
Expand Down Expand Up @@ -63,6 +112,7 @@ For example, the model name is `UserOrder`, the table name is `user_orders`.
| Offset | [Offset](#Offset) |
| Order | [Order](#Order) |
| OrWhere | [OrWhere](#Where) |
| Paginate | [Paginate](#Paginate) |
| Pluck | [Query single column](#Query-Single-Column) |
| Raw | [Execute native SQL](#Execute-Native-SQL) |
| Rollback | [Rollback transaction](#Transaction) |
Expand Down Expand Up @@ -214,6 +264,16 @@ facades.Orm.Query().Where("name = ?", "tom").Order("sort asc").Order("id desc").
// SELECT * FROM users WHERE name = "tom" order sort asc, id desc;
```

### Paginate

```go
var users []models.User
var total int64
facades.Orm.Query().Paginate(1, 10, &users, &total)
// SELECT count(*) FROM `users`;
// SELECT * FROM `users` LIMIT 10;
```

### Query Single Column

```go
Expand Down Expand Up @@ -433,7 +493,7 @@ type Result struct {
}

var result Result
db.Raw("SELECT id, name, age FROM users WHERE name = ?", "tom").Scan(&result)
facades.Orm.Query().Raw("SELECT id, name, age FROM users WHERE name = ?", "tom").Scan(&result)
```

### Execute Native Update SQL
Expand Down
6 changes: 6 additions & 0 deletions digging-deeper/authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ You can configure default guard and multiple guards in the `config/auth.go` file

You can configure parameters of JWT in the `config/jwt.go` file, such as `secret`, `ttl`, `refresh_ttl`.

## Generate JWT Token

```
go run . artisan jwt:secret
```

## Generate Token Using User

You can generate Token by Model, there is no extra configuration if the model use `orm.Model`, otherwise, you need to configure Tag on the model permary key filed, for example:
Expand Down
3 changes: 2 additions & 1 deletion digging-deeper/cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ Goravel provides an expandable cache module, this module can be operated using `

## Configuration

Make all custom configurations in `config/cache.go`. Different cache drivers are allowed to be configured. By default, `redis` is used. You can also customize the driver.
Make all custom configurations in `config/cache.go`. Different cache drivers are allowed to be configured. By default, `memory` is used. You can also customize the driver.

## Available Cache Drivers

| Name | Description |
| -------- | ------------ |
| `memory` | Memory drive, restarting service will clear cache |
| `redis` | Redis drive |
| `custom` | Custom drive |

Expand Down
26 changes: 24 additions & 2 deletions getting-started/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,46 @@ go run . artisan key:generate
go run .
```

## Specify .env File To Start Service

```
go run . --env=../.env
```

### Live reload

Built-in [cosmtrek/air](https://github.com/cosmtrek/air) configuration file which can be used directly.
Built-in [cosmtrek/air](https://github.com/cosmtrek/air) configuration file which can be used directly:

```
air
```

If you are using Windows system, you need to modify the `.air.toml` file in the root directory, add the `.exe` suffix to the following two lines:

```
[build]
bin = "./storage/temp/main.exe"
cmd = "go build -o ./storage/temp/main.exe ."
```

## Configuration

### Configuration files

All configuration files of the Goravel framework are placed in the `config` directory. All configuration items has annotations, you can adjust it according to your needs.

### Application key
### Generate Application key

You need to generate the application key after Goravel is installed locally. Running the command below, a 32-bit string will be generated on the `APP_KEY` key in the `.env` file. This key is mainly used for data encryption and decryption.

```
go run. artisan key:generate
```

### Generate JWT Token

You need to generate JWT Token if you use [Authentication](../digging-deeper/authentication.md).

```
go run . artisan jwt:secret
```
6 changes: 6 additions & 0 deletions the-basics/controllers.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,9 @@ func Web() {
facades.Route.Get("/{id}", userController.Show)
}
```

### Create Controller

```
go run . artisan make:controller UserController
```
5 changes: 5 additions & 0 deletions the-basics/middleware.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ There are some middleware available in Goravel:
| ------------------------------------------------- | ------------- |
| github.com/goravel/framework/http/middleware/Cors | across domain |

### Create Middleware By Command
```
go run . artisan make:middleware Cors
```

## Register Middlewares

### Global Middlewares
Expand Down
12 changes: 12 additions & 0 deletions the-basics/response.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ ctx.Response().Json(http.OK, struct {
})
```

## Custom Return

```go
ctx.Response().Data(http.StatusOK, "text/html; charset=utf-8", []byte("<b>Goravel</b>"))
```

## Response File

```go
Expand Down Expand Up @@ -68,6 +74,12 @@ ctx.Response().Success().Json(contracthttp.Json({
}))
```

## Redirect

```go
ctx.Response().Redirect(http.StatusMovedPermanently, "https://goravel.dev")
```

## Get Response

You can get all information of `ctx.Response()`, commonly used in HTTP middleware:
Expand Down
6 changes: 4 additions & 2 deletions the-basics/validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,12 @@ import (
"github.com/goravel/framework/validation"
)

validator, err := facades.Validation.Make(input, rules, validation.PrepareForValidation(func(data validationcontract.Data){
validator, err := facades.Validation.Make(input, rules, validation.PrepareForValidation(func(data validationcontract.Data) error {
if name, exist := data.Get("name"); exist {
data.Set("name", int(name))
return data.Set("name", int(name))
}

return nil
}))
```

Expand Down
9 changes: 9 additions & 0 deletions upgrade/history.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# History Upgrade

- [Upgrading To v1.7 From v1.6](v1.7.md)
- [Upgrading To v1.6 From v1.5](v1.6.md)
- [Upgrading To v1.5 From v1.4](v1.5.md)
- [Upgrading To v1.4 From v1.3](v1.4.md)
- [Upgrading To v1.3 From v1.2](v1.3.md)
- [Upgrading To v1.2 From v1.1](v1.2.md)
- [Upgrading To v1.1 From v1.0](v1.1.md)
Loading

0 comments on commit f73facc

Please sign in to comment.