A peewee extension for TiDB.
Project description
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
Project details
Release history Release notifications | RSS feed
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 peewee-tidb-0.1.1.tar.gz.
File metadata
- Download URL: peewee-tidb-0.1.1.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4917ef994578d85f7cbcbeadc01aefbb5fddabf3ca96ce6e54b59886a97e363f
|
|
| MD5 |
d9b0e3416ddc48abede8d1ed339671c8
|
|
| BLAKE2b-256 |
630356e0c41b5fe38f374cf0ab16cfd6b87407eeefb89cd58838ab8d41770344
|
File details
Details for the file peewee_tidb-0.1.1-py3-none-any.whl.
File metadata
- Download URL: peewee_tidb-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
94d26b61669e78646f3c28a30ac8b7e173223b6136327f76488a47275f67c732
|
|
| MD5 |
4e9d7dad24ff32405986094aa3a28af1
|
|
| BLAKE2b-256 |
15be6e1c425138b937159d9834a229d95254560de1d5212e2e4b17efdf0e78dd
|