peewee-tidb
TiDB dialect for peewee.
Installation
Install from PyPI
pip install peewee-tidb
Install from source
pip install git+https://github.com/wd0517/peewee-tidb.git@main
Usage
from peewee import *
from peewee_tidb import TidbDatabase
db = TiDBDatabase(
'peewee',
host='127.0.0.1',
port=4000,
user='root',
password=''
)
Using AUTO_RANDOM
AUTO_RANDOM is a feature in TiDB that generates unique IDs for a table automatically. It is similar to AUTO_INCREMENT, but it can avoid write hotspot in a single storage node caused by TiDB assigning consecutive IDs. It also have some restrictions, please refer to the documentation.
from peewee_tidb import BigAutoRandomField
class MyModel(BaseModel):
id = BigAutoRandomField(shard_bits=6, range=54, primary_key=True)
Note
AUTO_RANDOMis supported after TiDB v3.1.0, and only support define withrangeafter v6.5.0, sorangewill be ignored if TiDB version is lower than v6.5.0.
Using AUTO_ID_CACHE
AUTO_ID_CACHE allow users to set the cache size for allocating the auto-increment ID, as you may know, TiDB guarantees that AUTO_INCREMENT values are monotonic (always increasing) on a per-server basis, but its value may appear to jump dramatically if an INSERT operation is performed against another TiDB Server, This is caused by the fact that each server has its own cache which is controlled by AUTO_ID_CACHE. But from TiDB v6.4.0, it introduces a centralized auto-increment ID allocating service, you can enable MySQL compatibility mode by set AUTO_ID_CACHE to 1 when creating a table without losing performance.
To use AUTO_ID_CACHE in peewee, you can set table_settings in Meta class.
class MyModel(BaseModel):
name = CharField(max_length=32, unique=True)
class Meta:
table_settings = "auto_id_cache=1;"
Some Known Issues
Metadata
Release files for peewee-tidb 0.1.1
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 | |
|---|---|---|---|---|
| peewee-tidb-0.1.1.tar.gz | 4.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| peewee_tidb-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.1 kB
Release files / peewee-tidb-0.1.1.tar.gz
| Download URL | peewee-tidb-0.1.1.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4917ef994578d85f7cbcbeadc01aefbb5fddabf3ca96ce6e54b59886a97e363f
|
|
BLAKE2b-256 checksum How to use checksums |
630356e0c41b5fe38f374cf0ab16cfd6b87407eeefb89cd58838ab8d41770344
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.6
|
Release files / peewee_tidb-0.1.1-py3-none-any.whl
| Download URL | peewee_tidb-0.1.1-py3-none-any.whl |
|---|---|
| Size | 4.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
94d26b61669e78646f3c28a30ac8b7e173223b6136327f76488a47275f67c732
|
|
BLAKE2b-256 checksum How to use checksums |
15be6e1c425138b937159d9834a229d95254560de1d5212e2e4b17efdf0e78dd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.6
|
Security for peewee-tidb 0.1.1
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.