peewee-tidb


Namepeewee-tidb JSON
Version 0.1.1 PyPI version JSON
download
home_page
SummaryA peewee extension for TiDB.
upload_time2023-10-22 00:31:20
maintainer
docs_urlNone
author
requires_python>=3.7
licenseMIT License
keywords peewee tidb
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # peewee-tidb

TiDB dialect for peewee.

## Installation

### Install from PyPI

```bash
pip install peewee-tidb
```

### Install from source

```bash
pip install git+https://github.com/wd0517/peewee-tidb.git@main
```

## Usage

```python
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`](https://docs.pingcap.com/tidb/stable/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](https://docs.pingcap.com/tidb/stable/auto-random#restrictions).

```python
from peewee_tidb import BigAutoRandomField

class MyModel(BaseModel):
    id = BigAutoRandomField(shard_bits=6, range=54, primary_key=True)
```

> **Note**
>
> `AUTO_RANDOM` is supported after TiDB v3.1.0, and only support define with `range` after v6.5.0, so `range` will be ignored if TiDB version is lower than v6.5.0.

### Using `AUTO_ID_CACHE`

[`AUTO_ID_CACHE`](https://docs.pingcap.com/tidb/stable/auto-increment#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*](https://docs.pingcap.com/tidb/stable/auto-increment#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.

```python
class MyModel(BaseModel):
    name = CharField(max_length=32, unique=True)

    class Meta:
        table_settings = "auto_id_cache=1;"
```

### Some Known Issues

- TiDB before v6.6.0 does not support FOREIGN KEY constraints([#18209](https://github.com/pingcap/tidb/issues/18209)).
- TiDB before v6.2.0 does not support SAVEPOINT([#6840](https://github.com/pingcap/tidb/issues/6840)).

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "peewee-tidb",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "peewee,tidb",
    "author": "",
    "author_email": "wd0517 <me@wangdi.ink>",
    "download_url": "https://files.pythonhosted.org/packages/63/03/56e0c41b5fe38f374cf0ab16cfd6b87407eeefb89cd58838ab8d41770344/peewee-tidb-0.1.1.tar.gz",
    "platform": null,
    "description": "# peewee-tidb\n\nTiDB dialect for peewee.\n\n## Installation\n\n### Install from PyPI\n\n```bash\npip install peewee-tidb\n```\n\n### Install from source\n\n```bash\npip install git+https://github.com/wd0517/peewee-tidb.git@main\n```\n\n## Usage\n\n```python\nfrom peewee import *\nfrom peewee_tidb import TidbDatabase\n\ndb = TiDBDatabase(\n    'peewee',\n    host='127.0.0.1',\n    port=4000,\n    user='root',\n    password=''\n)\n```\n\n### Using `AUTO_RANDOM`\n\n[`AUTO_RANDOM`](https://docs.pingcap.com/tidb/stable/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](https://docs.pingcap.com/tidb/stable/auto-random#restrictions).\n\n```python\nfrom peewee_tidb import BigAutoRandomField\n\nclass MyModel(BaseModel):\n    id = BigAutoRandomField(shard_bits=6, range=54, primary_key=True)\n```\n\n> **Note**\n>\n> `AUTO_RANDOM` is supported after TiDB v3.1.0, and only support define with `range` after v6.5.0, so `range` will be ignored if TiDB version is lower than v6.5.0.\n\n### Using `AUTO_ID_CACHE`\n\n[`AUTO_ID_CACHE`](https://docs.pingcap.com/tidb/stable/auto-increment#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*](https://docs.pingcap.com/tidb/stable/auto-increment#mysql-compatibility-mode) by set `AUTO_ID_CACHE` to `1` when creating a table without losing performance.\n\nTo use `AUTO_ID_CACHE` in peewee, you can set `table_settings` in `Meta` class.\n\n```python\nclass MyModel(BaseModel):\n    name = CharField(max_length=32, unique=True)\n\n    class Meta:\n        table_settings = \"auto_id_cache=1;\"\n```\n\n### Some Known Issues\n\n- TiDB before v6.6.0 does not support FOREIGN KEY constraints([#18209](https://github.com/pingcap/tidb/issues/18209)).\n- TiDB before v6.2.0 does not support SAVEPOINT([#6840](https://github.com/pingcap/tidb/issues/6840)).\n",
    "bugtrack_url": null,
    "license": "MIT License",
    "summary": "A peewee extension for TiDB.",
    "version": "0.1.1",
    "project_urls": {
        "Bug Reports": "https://github.com/wd0517/peewee-tidb/issues",
        "Homepage": "https://github.com/wd0517/peewee-tidb",
        "Source": "https://github.com/wd0517/peewee-tidb"
    },
    "split_keywords": [
        "peewee",
        "tidb"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "15be6e1c425138b937159d9834a229d95254560de1d5212e2e4b17efdf0e78dd",
                "md5": "4e9d7dad24ff32405986094aa3a28af1",
                "sha256": "94d26b61669e78646f3c28a30ac8b7e173223b6136327f76488a47275f67c732"
            },
            "downloads": -1,
            "filename": "peewee_tidb-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4e9d7dad24ff32405986094aa3a28af1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 4648,
            "upload_time": "2023-10-22T00:31:18",
            "upload_time_iso_8601": "2023-10-22T00:31:18.762944Z",
            "url": "https://files.pythonhosted.org/packages/15/be/6e1c425138b937159d9834a229d95254560de1d5212e2e4b17efdf0e78dd/peewee_tidb-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "630356e0c41b5fe38f374cf0ab16cfd6b87407eeefb89cd58838ab8d41770344",
                "md5": "d9b0e3416ddc48abede8d1ed339671c8",
                "sha256": "4917ef994578d85f7cbcbeadc01aefbb5fddabf3ca96ce6e54b59886a97e363f"
            },
            "downloads": -1,
            "filename": "peewee-tidb-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "d9b0e3416ddc48abede8d1ed339671c8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 4461,
            "upload_time": "2023-10-22T00:31:20",
            "upload_time_iso_8601": "2023-10-22T00:31:20.240430Z",
            "url": "https://files.pythonhosted.org/packages/63/03/56e0c41b5fe38f374cf0ab16cfd6b87407eeefb89cd58838ab8d41770344/peewee-tidb-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-22 00:31:20",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "wd0517",
    "github_project": "peewee-tidb",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "peewee-tidb"
}
        
Elapsed time: 0.13491s