leancloud-better-storage的Python项目详细描述
leancloud更好的存储python
更好的leancloud存储包装。简单轻便。
安装
通过easy_install
或pip
安装。
$ pip install leancloud-better-storage
快速启动
模型声明和查询就像sqlalchemy一样,请参见下面的示例。
模型声明
fromleancloud_better_storage.storage.modelsimportModelfromleancloud_better_storage.storage.fieldsimportFieldclassProduct(Model):name=Field('product_name',nullable=False)price=Field(nullable=False)field3=Field(nullable=False,default=1)field4=Field()
积垢操作
创建
product=Product.create(name='FirstProduct',price=100)product.commit()# v0.1.3 now default null valueassertproduct.field4isNone
读取和查询
# find by simple equationproducts=Product.query().filter_by(name='product').find()# support >,<,>=,<=,==.but not support compare to another field.products=Product.query().filter(Product.price<10).find()# support and_(), or_().products=Product.query().filter(Product.created_at>datetime(2018,8,1)).and_() \
.filter(Product.created_at<datetime(2018,9,1)).find()# find support limit and skip argument.products=Product.query().order_by(Product.price.desc).find(limit=10)# also support pagination, start from page 0 and 10 elements per page.pages=Product.query().paginate(0,10)forpageinpages:print(page.items)# access elements
更新
product=Product.query().filter_by(name='FirstProduct').first()product.name='LastProduct'product.commit()
删除
product=Product.query().filter_by(name='FirstProduct').first()product.drop()
更新日志
欢迎加入QQ群-->: 979659372
推荐PyPI第三方库