Better ORM wrapper of leancloud storage python sdk.
Project description
leancloud-better-storage-python
better leancloud storage wrapper. Simple and lightweight.
Installation
install by easy_install
or pip
.
$ pip install leancloud-better-storage
Quick start
Model declaration and query just like SQLAlchemy, see example below.
Model declaration
from leancloud_better_storage.storage.models import Model
from leancloud_better_storage.storage.fields import Field
class Product(Model):
name = Field('product_name', nullable=False)
price = Field(nullable=False)
field3 = Field(nullable=False, default=1)
field4 = Field()
CRUD operations
Create
product = Product.create(name='FirstProduct',price=100)
product.commit()
# v0.1.3 now default null value
assert product.field4 is None
Read & Query
# find by simple equation
products = 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)
for page in pages:
print(page.items) # access elements
Update
product = Product.query().filter_by(name='FirstProduct').first()
product.name = 'LastProduct'
product.commit()
Delete
product = Product.query().filter_by(name='FirstProduct').first()
product.drop()
Update log
- 0.1.7 修复初始值 null 覆盖了存储服务生成字段值的问题。
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
Built Distribution
File details
Details for the file leancloud-better-storage-0.1.7.tar.gz
.
File metadata
- Download URL: leancloud-better-storage-0.1.7.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8471ebe1cba5e7fe68dec4366800b7844b2451aec96d2c6d3a62ca3be505c486 |
|
MD5 | e5af866d055edc08c55d00d3d502e298 |
|
BLAKE2b-256 | d546dcd435d71a8960076caf21b792343f9c91ad654f47a157b91d6e91095bbb |
File details
Details for the file leancloud_better_storage-0.1.7-py3-none-any.whl
.
File metadata
- Download URL: leancloud_better_storage-0.1.7-py3-none-any.whl
- Upload date:
- Size: 11.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 874e37c7f93221bc5e76ce61c023de6aaec6a85a6e06b721da29361360ca066c |
|
MD5 | 69e37208f51dc05c4d449c52dc3a6b8f |
|
BLAKE2b-256 | 1ef5df83e681a67a32226d135192697ab11c385d4648ba568ad118056b132d7e |