更新readme:数据迁移和生成CRUD,路由配置
This commit is contained in:
parent
5af56e956c
commit
afe3b042d9
@ -18,11 +18,11 @@ Typer 官方文档:https://typer.tiangolo.com/
|
||||
|
||||
SQLAlchemy 2.0 (官方): https://docs.sqlalchemy.org/en/20/intro.html#installation
|
||||
|
||||
SQLAlchemy 1.4 迁移到 2.0
|
||||
(官方):https://docs.sqlalchemy.org/en/20/changelog/whatsnew_20.html#whatsnew-20-orm-declarative-typing
|
||||
SQLAlchemy 1.4 迁移到 2.0 (官方):https://docs.sqlalchemy.org/en/20/changelog/whatsnew_20.html#whatsnew-20-orm-declarative-typing
|
||||
|
||||
PEP 484 语法(官方):https://peps.python.org/pep-0484/
|
||||
|
||||
|
||||
## 项目结构
|
||||
|
||||
使用的是仿照 Django 项目结构:
|
||||
@ -133,7 +133,6 @@ http://127.0.0.1:9000/docs
|
||||
```
|
||||
|
||||
Git更新ignore文件直接修改gitignore是不会生效的,需要先去掉已经托管的文件,修改完成之后再重新添加并提交。
|
||||
|
||||
```
|
||||
第一步:
|
||||
git rm -r --cached .
|
||||
@ -148,9 +147,7 @@ git commit -m "clear cached"
|
||||
```
|
||||
|
||||
## 新的数据迁移
|
||||
|
||||
执行数据库迁移命令(终端执行)
|
||||
|
||||
- 新建模型:
|
||||
- 在你的app目录下新建一个models目录,__init__.py导入你需要迁移的models
|
||||
```python
|
||||
@ -242,36 +239,36 @@ urlpatterns = [
|
||||
# 日期查询
|
||||
# 值的类型:str
|
||||
# 值得格式:%Y-%m-%d:2023-05-14
|
||||
字段名称 = ("date", 值)
|
||||
字段名称=("date", 值)
|
||||
|
||||
# 模糊查询
|
||||
# 值的类型: str
|
||||
字段名称 = ("like", 值)
|
||||
字段名称=("like", 值)
|
||||
|
||||
# in 查询
|
||||
# 值的类型:list
|
||||
字段名称 = ("in", 值)
|
||||
字段名称=("in", 值)
|
||||
|
||||
# 时间区间查询
|
||||
# 值的类型:tuple 或者 list
|
||||
字段名称 = ("between", 值)
|
||||
字段名称=("between", 值)
|
||||
|
||||
# 月份查询
|
||||
# 值的类型:str
|
||||
# 值的格式:%Y-%m:2023-05
|
||||
字段名称 = ("month", 值)
|
||||
字段名称=("month", 值)
|
||||
|
||||
# 不等于查询
|
||||
字段名称 = ("!=", 值)
|
||||
字段名称=("!=", 值)
|
||||
|
||||
# 大于查询
|
||||
字段名称 = (">", 值)
|
||||
字段名称=(">", 值)
|
||||
|
||||
# 等于 None
|
||||
字段名称 = ("None")
|
||||
字段名称=("None")
|
||||
|
||||
# 不等于 None
|
||||
字段名称 = ("not None")
|
||||
字段名称=("not None")
|
||||
```
|
||||
|
||||
代码部分:
|
||||
@ -325,15 +322,15 @@ def __dict_filter(self, **kwargs) -> list[BinaryExpression]:
|
||||
查询所有用户id为1或2或 4或6,并且email不为空,并且名称包括李:
|
||||
|
||||
```python
|
||||
users = UserDal(db).get_datas(limit=0, id=("in", [1, 2, 4, 6]), email=("not None",), name=("like", "李"))
|
||||
users = UserDal(db).get_datas(limit=0, id=("in", [1,2,4,6]), email=("not None", ), name=("like", "李"))
|
||||
|
||||
# limit=0:表示返回所有结果数据
|
||||
# 这里的 get_datas 默认返回的是 pydantic 模型数据
|
||||
# 如果需要返回用户对象列表,使用如下语句:
|
||||
users = UserDal(db).get_datas(
|
||||
limit=0,
|
||||
id=("in", [1, 2, 4, 6]),
|
||||
email=("not None",),
|
||||
id=("in", [1,2,4,6]),
|
||||
email=("not None", ),
|
||||
name=("like", "李"),
|
||||
v_return_objs=True
|
||||
)
|
||||
@ -344,7 +341,7 @@ users = UserDal(db).get_datas(
|
||||
查询第一页,每页两条数据,并返回总数,同样可以通过 `get_datas` 实现原始查询方式:
|
||||
|
||||
```python
|
||||
v_where = [VadminUser.id.in_([1, 2, 4, 6]), VadminUser.email.isnot(None), VadminUser.name.like(f"%李%")]
|
||||
v_where = [VadminUser.id.in_([1,2,4,6]), VadminUser.email.isnot(None), VadminUser.name.like(f"%李%")]
|
||||
users, count = UserDal(db).get_datas(limit=2, v_where=v_where, v_return_count=True)
|
||||
|
||||
# 这里的 get_datas 默认返回的是 pydantic 模型数据
|
||||
@ -353,7 +350,7 @@ users, count = UserDal(db).get_datas(
|
||||
limit=2,
|
||||
v_where=v_where,
|
||||
v_return_count=True
|
||||
v_return_objs = True
|
||||
v_return_objs=True
|
||||
)
|
||||
```
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user