-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: page query api add order condition
- Loading branch information
Showing
4 changed files
with
56 additions
and
2 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
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,27 @@ | ||
建表注意事项: | ||
|
||
1. 除了多对多关联表之外,其他所有表都应具备 `created_at`、`updated_at` 和 `deleted_at` 字段,建表语句模版: | ||
|
||
```sql | ||
create table table_name ( | ||
id serial primary key not null, | ||
|
||
-- other columns... | ||
|
||
created_at timestamptz not null default now(), | ||
updated_at timestamptz not null default now(), | ||
deleted_at timestamptz null default null | ||
); | ||
``` | ||
|
||
2. 多对多关联表只需具备两个关联 ID 字段,不应该包含 `created_at`、`updated_at` 和 `deleted_at` 字段。同时,关联表只需建表,无需定义 Model,需要进行多对多关联的 Model 只需要声明 `gorm:"many2many:xxx"` 标签即可,具体使用请查阅 GORM 文档。以下是用户角色关联表的例子: | ||
|
||
```sql | ||
create table users_roles ( | ||
user_id int not null, | ||
role_id int not null | ||
); | ||
create unique index users_roles_user_id_role_id on users_roles(user_id, role_id); | ||
``` | ||
|
||
3. Go 结构体字段默认取零值,为了方便处理请求参数验证,尽量不要使用零值作为数据表字段的值。例如,使用 `int` 类型的 `1 2` 代替 `bool` 类型的 `true false`,因为收到 `false` 无法判知是否为用户漏传。 |
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,27 @@ | ||
Notes on table creation: | ||
|
||
1. Except for many-to-many association tables, all other tables should have `created_at`, `updated_at` and `deleted_at` fields. Table creation statement template: | ||
|
||
```sql | ||
create table table_name ( | ||
id serial primary key not null, | ||
|
||
-- other columns... | ||
|
||
created_at timestamptz not null default now(), | ||
updated_at timestamptz not null default now(), | ||
deleted_at timestamptz null default null | ||
); | ||
``` | ||
|
||
2. Many-to-many association tables only need two association ID fields and should not contain `created_at`, `updated_at` and `deleted_at` fields. And association tables don't need not to define models. The model that need many-to-many associations only need to declare the `gorm:"many2many:xxx"` tag. For specific usage, please refer to the GORM documentation. The following is an example of a user-role association table: | ||
```sql | ||
create table users_roles ( | ||
user_id int not null, | ||
role_id int not null | ||
); | ||
create unique index users_roles_user_id_role_id on users_roles(user_id, role_id); | ||
``` | ||
3. Go structure fields take zero values by default. To facilitate request parameter validation, try not to use zero values as the values of data table fields. For example, use `1 2` of type `int` instead of `true false` of type `bool`, because if `false` is received, it is impossible to determine whether it is a user miss. |
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