mongodb,支持μmongo odm的sanic框架

sanic-mongodb-extension的Python项目详细描述


支持μmongo odm的mongodb,支持sanic框架

功能

  • 使用motor_asyncio包对MongoDB进行异步查询
  • uMongoodm很好地集成,因此您可以在项目中轻松地使用它

安装

此软件包应使用pip:

pip install sanic-mongodb-extension

示例

#!/usr/bin/env python3fromsanicimportSanic,responsefromsanic_mongodb_extimportMongoDbExtensionfromumongoimportInstance,Document,MotorAsyncIOInstancefromumongo.fieldsimportStringFieldapp=Sanic(__name__)# Configuration for MongoDB and uMongoapp.config.update({"MONGODB_DATABASE":"app",# Make ensure that the `app` database is really exists"MONGODB_URI":"mongodb://root:root@mongodb:27017","LAZY_UMONGO":MotorAsyncIOInstance(),})# uMongo client is available as `app.mongodb` or `app.extensions['mongodb']`.# The lazy client will be available as `app.lazy_mongodb` only when the database was specified,# and which is a great choice for the structured projects.MongoDbExtension(app)# Describe the model@app.lazy_umongo.registerclassArtist(Document):name=StringField(required=True,allow_none=False)# And use it later for APIs@app.route("/")asyncdefhandle(request):artist=Artist(name="A new rockstar!")awaitartist.commit()returnresponse.json(artist.dump())if__name__=='__main__':app.run(host='0.0.0.0',port=8000)

许可证

sanic mongodb扩展是在bsd许可下发布的。有关详细信息,请阅读LICENSE文件。

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

推荐PyPI第三方库


热门话题
如何下载多个。java中的PDF文件   linux Java打开文件,形成实际用户主页~/   java如何在时间线内维护TableView选择?   java Hibernate注释@Where vs@WhereJoinTable   Java读/写访问异常FileNotFoundException(访问被拒绝)   继承在Java中是否可以扩展最后一个类?   Android HttpClient使用java使应用程序崩溃。lang.OutOfMemoryError:pthread_create   java为什么即使我在proguardproject中添加了jar文件,也会出现这种错误。txt?   如果添加JButton,swing Java FocusListener和KeyListener将无法工作   java使用solrj检索json格式的SolrDocument   使用Microsoft Visual Studio代码进行Java编程   java NoClassDefFoundError:org/apache/log4j/Logger   哈希集中包含相等对象的java   java中的参数化构造函数是否需要有一个主体?   java类似于NetBeans不必要的代码检测器   Java实践问题   java Blackberry“[projectname].调试文件丢失”和“I/O错误:找不到程序”jar