API Star的Peewee集成。

apistar-peewee-orm的Python项目详细描述


API星形窥视表

Build StatuscodecovPyPI version

  • 版本:0.3.6
  • 状态:生产/稳定
  • 作者:joséantonio perdiguero lópez

API Star的Peewee集成。

功能

此库提供:

  • 根据视图中的异常处理connectionscommit/rollback行为的事件挂钩。
  • 迁移支持与它们交互的命令行界面。

快速启动

安装API Star Peewee orm:

pip install apistar-peewee-orm

创建一个api之星应用程序,添加组件和事件挂钩:

fromapistarimportAppfromapistar_peewee_ormimportPeeweeDatabaseComponent,PeeweeTransactionHookroutes=[]components=[PeeweeDatabaseComponent(url='sqlite://'),]event_hooks=[PeeweeTransactionHook(),]app=App(routes=routes,components=components,event_hooks=event_hooks)

您的模型现在应该继承自此库中定义的基本模型:

importpeeweefromapistar_peewee_ormimportModelclassPuppyModel(Model):name=peewee.CharField()

完整示例

importtypingimportpeeweefromapistarimportApp,http,Route,types,validatorsfromapistar_peewee_ormimportModel,PeeweeDatabaseComponent,PeeweeTransactionHookclassPuppyModel(Model):name=peewee.CharField()classPuppyType(types.Type):id=validators.Integer(allow_null=True,default=None)name=validators.String()deflist_puppies()->typing.List[PuppyType]:return[PuppyType(puppy)forpuppyinPuppyModel.select()]defcreate_puppy(puppy:PuppyType,raise_exception:http.QueryParam)->http.JSONResponse:ifraise_exception:raiseExceptionmodel=PuppyModel.create(**puppy)returnhttp.JSONResponse(PuppyType(model),status_code=201)routes=[Route('/puppy/','POST',create_puppy),Route('/puppy/','GET',list_puppies),]components=[PeeweeDatabaseComponent(url='sqlite://'),]event_hooks=[PeeweeTransactionHook(),]app=App(routes=routes,components=components,event_hooks=event_hooks)

cli应用程序

将与此库一起安装一个应用程序,以提供对迁移和某些其他功能的完全支持 皮威和API之星。

$ apistar-peewee-orm --help

usage: apistar-peewee-orm [-h] [-s SETTINGS] [-q | -v] [--dry-run]
                          {status,upgrade,downgrade,merge,create} ... [app]

positional arguments:
  app                   API Star application path
                        (<package>.<module>:<variable>)

optional arguments:
  -h, --help            show this help message and exit
  -s SETTINGS, --settings SETTINGS
                        Module or object with Clinner settings in format
                        "package.module[:Object]"
  -q, --quiet           Quiet mode. No standard output other than executed
                        application
  -v, --verbose         Verbose level (This option is additive)
  --dry-run             Dry run. Skip commands execution, useful to check
                        which commands will be executed and execution order

Commands:
  {status,upgrade,downgrade,merge,create}
    status              Database migrations and models status.
    upgrade             Run database migrations sequentially.
    downgrade           Rollback database migrations sequentially.
    merge               Merge all migrations into a single one.
    create              Create a new migration. If a module is provided then
                        the migration will be automatically generated,
                        otherwise the migration will be empty.

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
带有嵌套JAR的java RCP ClassNotFoundException   java在输入框中设置默认值,crud应用程序使用spring   java如何在Heroku中使用fs创建新文件   java将JPanel放在JFrame中   java这个正则表达式会匹配“i.imgur.com/xxx”吗?   java在片段内创建RecylerView,而无需在Android中设置片段   Android上Groovy导致java错误的双精度浮点精度损失   swing Java查找JFrame属于JPanel的内容   java Spring junit自连线自定义类本身必须有构造函数吗?   java textswitcher支持前面的文本   从Android客户端到JAXRS的java Post自定义对象   java如何检索JSON数据并使用MPAndroidChart绘制折线图,以及在安卓上的改进   拒绝用户“root”@“localhost”的java c3p0访问(使用密码“是”)   使用Selenium Webdriver自动化ExtJS应用程序时java面临的问题