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.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | d49698369c272d29942bd94f0359f12895012464958aa42a736273d349857a57 |
|
MD5 | 608ce2fe094b6d78480eea0a0613ab63 |
|
BLAKE2b-256 | d6c77b4618d5cd7b11d2801637e60b1ed95da84c0201a27c0b7cddbc330c8798 |
Close
Hashes for leancloud_better_storage-0.1.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b46bd5f38c581bd7893251ad13234546df80072ec290c02cffec8cb46229013 |
|
MD5 | 09640be88d5221618ef42fd529a49852 |
|
BLAKE2b-256 | df39ed77e626d206dacc529f29f30b259274498f75087616b2e300636afc8f42 |