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.5.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5eeaec1652515d78cdc432003483821320ead57ea57247df399318e59a7abc93 |
|
MD5 | 79c7c8659161dd18806c0a5c48c0df3e |
|
BLAKE2b-256 | 4f7ac2f350584aa754b1c538289536118a7de7665012d44156f4ee3fe50b60bf |
Close
Hashes for leancloud_better_storage-0.1.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d30054f6409df0f4968762e1b441ca02537e6de2aab653aee6405657c470988 |
|
MD5 | 3fffd07bb2ea26b260d8579608ca9dc4 |
|
BLAKE2b-256 | c3d7f7b4d8285229ecf6ef1144b1cffdef174896a7bbdae5a7b7dd3a683b2c72 |