Skip to content

Commit 8cbb06d

Browse files
committed
update docs
1 parent 7a2b66e commit 8cbb06d

File tree

5 files changed

+634
-632
lines changed

5 files changed

+634
-632
lines changed

docs/.vuepress/sidebar.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ export const mySidebar: ThemeSidebarMulti = {
2929
collapsed: false,
3030
prefix: 'reference/',
3131
items: [
32+
{ text: '模型', link: 'model' },
33+
{ text: 'Schema', link: 'schema' },
3234
{ text: '路由', link: 'router' },
3335
{ text: 'CRUD', link: 'CRUD' },
34-
{ text: 'Schema', link: 'schema' },
35-
{ text: '操作人信息', link: '/planet', icon: 'fluent-color:receipt-16' },
3636
{ text: '分页', link: 'pagination' },
3737
{ text: '接口响应', link: 'response' },
3838
{ text: '自定义异常', link: '/planet', icon: 'fluent-color:receipt-16' },

docs/backend/reference/CRUD.md

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -20,56 +20,3 @@ fba 遵循以下命名规范:
2020
- 创建:`create()`
2121
- 更新:`update()`
2222
- 删除:`delete()`
23-
24-
## Mixin
25-
26-
CRUD Mixin 位于 `backend/common/model.py` 文件中
27-
28-
### 主键
29-
30-
我们未提供自动主键模式,而是必须通过手动定义的方式进行主键声明
31-
32-
```python
33-
# 通用 Mapped 类型主键, 需手动添加,参考以下使用方式
34-
# MappedBase -> id: Mapped[id_key]
35-
# DataClassBase && Base -> id: Mapped[id_key] = mapped_column(init=False)
36-
id_key = Annotated[
37-
int, mapped_column(primary_key=True, index=True, autoincrement=True, sort_order=-999, comment='主键id')
38-
]
39-
```
40-
41-
### 日期时间
42-
43-
日期时间 Mixin 将自动集成到 Base 类中,如果模型父类为 Base,将自动应用
44-
45-
```python
46-
class DateTimeMixin(MappedAsDataclass):
47-
"""日期时间 Mixin 数据类"""
48-
49-
created_time: Mapped[datetime] = mapped_column(
50-
DateTime(timezone=True), init=False, default_factory=timezone.now, sort_order=999, comment='创建时间'
51-
)
52-
updated_time: Mapped[datetime | None] = mapped_column(
53-
DateTime(timezone=True), init=False, onupdate=timezone.now, sort_order=999, comment='更新时间'
54-
)
55-
```
56-
57-
### 数据类基类
58-
59-
[MappedAsDataclass](https://docs.sqlalchemy.org/en/20/orm/dataclasses.html#orm-declarative-native-dataclasses)
60-
61-
声明性数据类基类, 它将带有数据类集成, 允许使用更高级配置;此基类适用于==不包含日期时间的模型=={.note}
62-
63-
```python
64-
class DataClassBase(MappedAsDataclass, MappedBase):
65-
__abstract__ = True
66-
```
67-
68-
### Base 基类
69-
70-
包含基础表结构的数据类基类;此基类适用于大多数模型
71-
72-
```python
73-
class Base(DataClassBase, DateTimeMixin):
74-
__abstract__ = True
75-
```

docs/backend/reference/model.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
title: 模型
3+
---
4+
5+
通用模型位于 `backend/common/model.py` 文件中
6+
7+
## 主键
8+
9+
我们未提供自动主键模式,而是必须通过手动定义的方式进行主键声明
10+
11+
```python
12+
# 通用 Mapped 类型主键, 需手动添加,参考以下使用方式
13+
# MappedBase -> id: Mapped[id_key]
14+
# DataClassBase && Base -> id: Mapped[id_key] = mapped_column(init=False)
15+
id_key = Annotated[
16+
int, mapped_column(primary_key=True, index=True, autoincrement=True, sort_order=-999, comment='主键id')
17+
]
18+
```
19+
20+
## Mixin 类
21+
22+
[Mixin](https://en.wikipedia.org/wiki/Mixin) 是一种面向对象编程概念, 使结构变得更加清晰
23+
24+
### 操作人
25+
26+
用于集成操作人信息到数据库表,使用方法请查看:[<Icon name="fluent-color:receipt-16" />操作人信息](../../planet.md)
27+
28+
```python
29+
class UserMixin(MappedAsDataclass):
30+
"""用户 Mixin 数据类"""
31+
32+
created_by: Mapped[int] = mapped_column(sort_order=998, comment='创建者')
33+
updated_by: Mapped[int | None] = mapped_column(init=False, default=None, sort_order=998, comment='修改者')
34+
```
35+
36+
### 日期时间
37+
38+
用于集成日期时间到数据库表,已集成在 [Base](#base-基类) 基类中
39+
40+
```python
41+
class DateTimeMixin(MappedAsDataclass):
42+
"""日期时间 Mixin 数据类"""
43+
44+
created_time: Mapped[datetime] = mapped_column(
45+
DateTime(timezone=True), init=False, default_factory=timezone.now, sort_order=999, comment='创建时间'
46+
)
47+
updated_time: Mapped[datetime | None] = mapped_column(
48+
DateTime(timezone=True), init=False, onupdate=timezone.now, sort_order=999, comment='更新时间'
49+
)
50+
```
51+
52+
## 数据类基类
53+
54+
[MappedAsDataclass](https://docs.sqlalchemy.org/en/20/orm/dataclasses.html#orm-declarative-native-dataclasses)
55+
56+
声明性数据类基类,它将带有数据类集成,允许使用更高级配置,==不包含日期时间=={.note}
57+
58+
```python
59+
class DataClassBase(MappedAsDataclass, MappedBase):
60+
61+
__abstract__ = True
62+
```
63+
64+
## Base 基类
65+
66+
声明性数据类基类, 带有数据类集成, 并包含日期时间
67+
68+
```python
69+
class Base(DataClassBase, DateTimeMixin):
70+
71+
__abstract__ = True
72+
```

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
"license": "MIT",
1515
"devDependencies": {
1616
"@vuepress/bundler-vite": "2.0.0-rc.20",
17-
"@vuepress/plugin-baidu-analytics": "2.0.0-rc.86",
17+
"@vuepress/plugin-baidu-analytics": "2.0.0-rc.91",
1818
"@vuepress/plugin-google-analytics": "2.0.0-rc.80",
19-
"@vuepress/plugin-umami-analytics": "2.0.0-rc.86",
19+
"@vuepress/plugin-umami-analytics": "2.0.0-rc.91",
2020
"vue": "^3.5.13",
2121
"vuepress": "2.0.0-rc.20",
22-
"vuepress-theme-plume": "1.0.0-rc.137"
22+
"vuepress-theme-plume": "1.0.0-rc.138"
2323
},
2424
"dependencies": {
25-
"@iconify/json": "^2.2.321",
25+
"@iconify/json": "^2.2.323",
2626
"@vueuse/core": "^12.8.2",
2727
"mermaid": "^11.6.0",
2828
"swiper": "^11.2.6"

0 commit comments

Comments
 (0)