Files
arlo/database/Readme.md
konjacpotato 2c8426d543 import arlo
2025-11-05 21:00:19 +08:00

25 lines
817 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 数据库模块
数据库模块主要分为三个部分database.py、model.py、crud.py。
- database.py包含数据库连接和会话管理。
- model.py定义数据库模型实体类包括表结构、字段类型、约束等。
- crud.py定义数据库操作函数包括增删改查等。
## 使用示例
```python
from database.database import get_session
from database.tscheduler.crud import get_task_by_id
with get_session() as db:
task = get_task_by_id(db, 1)
print(task)
print(task.id)
```
## 新增数据表流程
新增数据表主要涉及模型定义和CRUD实现。
1. 在database包下创建以数据表命名的包名然后在里面创建model.py和crud.py。
2. model.py 定义数据库模型
3. crud.py 定义数据库操作函数