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()
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
Close
Hashes for leancloud-better-storage-0.1.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f145b8855514530ee61fccdafb5ebdefedb9f9615fe87df88d4caabf10dc424 |
|
MD5 | 846db415a5d3247c47e56fc00ce85479 |
|
BLAKE2b-256 | a7d5fb9106840094c3deed52365658fdda72e17bfadcbb93a4f79db2cc68f28b |
Close
Hashes for leancloud_better_storage-0.1.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d9ce126344bc495e7786928951cfe631f4fd50b7fa5efab41da90b06f9f3deb |
|
MD5 | ec5fef5b5b2038614a4c2cfc3de7f6bd |
|
BLAKE2b-256 | 3a8c6b3ed8e9ebdd2fc81846f4deb748236e48a2e0970bfff638e084d10b64bf |