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
Metadata
Release files for crystaldb 1.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| crystaldb-1.1.2.tar.gz | 23.4 kB | Without provenance | Details for crystaldb-1.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| crystaldb-1.1.2-py3-none-any.whl | Python 3 | none | any | Details for crystaldb-1.1.2-py3-none-any.whl |
Total release size: 44.4 kB
Release files / crystaldb-1.1.2.tar.gz
| Download URL | crystaldb-1.1.2.tar.gz |
|---|---|
| Size | 23.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dc5b37e7e933f84df736b05698b3594bcae9df90fbaf47210f0b6d8d7dc9f9e0
|
|
BLAKE2b-256 checksum How to use checksums |
6435dde99a53cb37b45e72f00f15d567d00a977c7dab8c8c12c7b9da822ecbe7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / crystaldb-1.1.2-py3-none-any.whl
| Download URL | crystaldb-1.1.2-py3-none-any.whl |
|---|---|
| Size | 20.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6f3de6ef78645c2ecca2265ee5c11d3cb597af6c99cacb538221237bb1d81ee0
|
|
BLAKE2b-256 checksum How to use checksums |
9df1011d72a5b49e02ca6c933f3ec98129ae271b4f385d1fe00bf455b95530c7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Security for crystaldb 1.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.