Skip to main content

快速开发后端API的路由组件,支持自动生成CRUD接口

Project description

zdpapi_router

快速开发后端API的路由组件,支持自动生成CRUD接口

说明:此项目基于zdpapi和zdpapi_mysql构建,如果使用有困难的同学,可以先去看这两个框架

本项目地址:https://github.com/zhangdapeng520/zdpapi_router

功能:

  • 自动生成新增单条数据路由
  • 自动生成新增多条数据路由
  • 自动生成删除单条数据路由
  • 自动生成删除多条数据路由
  • 自动生成修改单条数据路由
  • 自动生成修改多条数据路由
  • 自动生成查询单条数据路由
  • 自动生成查询多条数据路由
  • 自动生成分页查询多条数据路由

一、快速入门

1.1 安装

pip install zdpapi_router

1.2 说明

如果您要直接使用示例代码,一定要确保本地安装了MySQL数据库,且创建了名为test的数据库。同时在test数据库中存在user表,该表有id和name两个字段。

如果您学习过我的另一个项目zdpapi_mysql,则直接运行里面的示例代码即可。

1.3 入门案例

将下面的代码复制到main.py中

from zdpapi_router import CRUDRouter
from zdpapi import ZApi
from pydantic import BaseModel

app = ZApi()


class UserSchema(BaseModel):
    id: int  # 必须包含ID,批量更新的时候要用到
    name: str


mysql_config = {
    "host": '127.0.0.1',
    "port": 3306,
    "user": 'root',
    "password": 'root',
    "db": 'test'
}
router = CRUDRouter(mysql_config=mysql_config,
                    table_name="user",
                    columns=["name"],
                    chinese_name="用户",
                    schema=UserSchema)
app = router.register(app)

if __name__ == '__main__':
    import uvicorn

    uvicorn.run("main:app", reload=True)

运行

python main.py

访问:http://127.0.0.1:8000/docs

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zdpapi_router-1.0.0.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

zdpapi_router-1.0.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file zdpapi_router-1.0.0.tar.gz.

File metadata

  • Download URL: zdpapi_router-1.0.0.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.7 CPython/3.8.8 Windows/10

File hashes

Hashes for zdpapi_router-1.0.0.tar.gz
Algorithm Hash digest
SHA256 3bc5748151a1f95c7f9e883b380652c9ad6a5f2511dad2c00a25974cf664667e
MD5 c68cc70e66770ab42ab322bba8ad1275
BLAKE2b-256 a0f2665b4dbabe3ac9344db271afb4a629821e83a384b583513e1a9efce46e9d

See more details on using hashes here.

File details

Details for the file zdpapi_router-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: zdpapi_router-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.7 CPython/3.8.8 Windows/10

File hashes

Hashes for zdpapi_router-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f8e00ec71dde6722412f343c23d31c9c5272d6cf5b64aa4da5034ab1f95fee97
MD5 2066c8a4fa39d33e5019a6590aebc923
BLAKE2b-256 91cc9a25c624f70ee0e6ac0e0914f61715d2ed9d84c4051bdd38092ab10d6462

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page