CrystalDB is a simple and small ORM and no need to provide a model.
Project description
CrystalDB
CrystalDB is a simple and small ORM. It has few concepts, making it easy to learn and intuitive to use.
- a small, expressive ORM, and no need to provide a model, so it will not be difficult for the problem of sub-library or sub-tables.
- python3.
- need mysql-client or pymysql or mysql.connector.
- currently only supports mysql.
Installation
From PyPi:
$ pip install crysyaldb
Basic Usage
-
Connect to the database:
import crystaldb db_host = '127.0.0.1' db_port = 3306 db_user = 'root' db_pass = '123' db_database = 'testdb' db_handle = crystaldb.database( dbn='mysql', host=db_host, port=db_port, user=db_user, passwd=db_pass, db=db_database, debug=True)
-
Create table: (Temporarily not supported, need to be completed by yourself)
for example:
CREATE TABLE `user` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `gender` varchar(16) DEFAULT NULL, `name` varchar(16) DEFAULT NULL, `birthday` varchar(16) DEFAULT NULL, `age` int(11) unsigned DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-
Create row:
values = { 'gender': 'girl', 'name': 'xiaoli_orm', 'birthday': '1982-08-02', 'age': 36 } result = db_handle.operator("user").insert(**values) print(result) # ==> 1 # If debug is True, the following log will be printed, time unit ms. # 0.3162 (1): INSERT INTO user (age, birthday, gender, name) VALUES (36, '1982-08-02', 'girl', 'xiaoli_orm')
-
Querying:
result = db_handle.select("user", ["name", "age"]).filter( age=36, gender="girl").query() print(result.__len__()) # count print(result) # <crystaldb.utils.IterBetter object at 0x1115246a0> for item in result: print(item) # <Storage {'name': 'xiaowang', 'age': 36}> print(item.name) # xiaowang # If debug is True, the following log will be printed, time unit ms. # 0.8579 (5): SELECT user.name, user.age FROM user WHERE user.age = 36 AND user.gender = 'girl'
-
Update row:
where = dict(name="xiaoli_orm") values = {'gender': 'boy', 'birthday': '1981-08-02', 'age': 37} result = db_handle.operator("user").update(where, **values) print(result) # 1 # If debug is True, the following log will be printed, time unit ms. # 0.4399 (1): UPDATE user SET age = 37, birthday = '1981-08-02', gender = 'boy' WHERE name = 'xiaoli_orm';
-
Delete row:
where = dict(name="xiaoyu", age=27) result = db_handle.operator("user").delete(where) # If debug is True, the following log will be printed, time unit ms. # 0.3782 (1): DELETE FROM user WHERE age = 27 AND name = 'xiaoyu';
-
Get Debug Queries:
print(db_handle.get_debug_queries_info) # {'run_time': '0.8247', 'sql': "SELECT user.name, user.age FROM user WHERE user.age = 36 AND user.gender = 'girl'"}
Documentation
Learning more
Check the documentation for more examples or read test cases in unit test code.
Change Log
Discussing
- submit issue
- email: fuzctc@gmail.com
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file crystaldb-1.1.2.tar.gz.
File metadata
- Download URL: crystaldb-1.1.2.tar.gz
- Upload date:
- Size: 23.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.20.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.7.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dc5b37e7e933f84df736b05698b3594bcae9df90fbaf47210f0b6d8d7dc9f9e0
|
|
| MD5 |
c93a7454b21a5a04b6a915fbb75e9cdb
|
|
| BLAKE2b-256 |
6435dde99a53cb37b45e72f00f15d567d00a977c7dab8c8c12c7b9da822ecbe7
|
File details
Details for the file crystaldb-1.1.2-py3-none-any.whl.
File metadata
- Download URL: crystaldb-1.1.2-py3-none-any.whl
- Upload date:
- Size: 20.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.20.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.7.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6f3de6ef78645c2ecca2265ee5c11d3cb597af6c99cacb538221237bb1d81ee0
|
|
| MD5 |
49346e44dc4228a9b695202bc8a0b289
|
|
| BLAKE2b-256 |
9df1011d72a5b49e02ca6c933f3ec98129ae271b4f385d1fe00bf455b95530c7
|