https://github.com/pingcap/sqlalchemy-tidb
https://github.com/pingcap/sqlalchemy-tidb
Last synced: 11 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/pingcap/sqlalchemy-tidb
- Owner: pingcap
- License: apache-2.0
- Archived: true
- Created: 2021-08-12T04:08:02.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2024-10-30T02:50:42.000Z (over 1 year ago)
- Last Synced: 2025-04-06T23:14:47.591Z (11 months ago)
- Language: Python
- Size: 63.5 KB
- Stars: 6
- Watchers: 30
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sqlalchemy-tidb
[](https://github.com/pingcap/sqlalchemy-tidb/actions/workflows/ci.yml)
This adds compatibility for [TiDB](https://github.com/pingcap/tidb) to SQLAlchemy.
## Supported versions
- TiDB 4.x and newer
- SQLAlchemy 1.4.x
- Python 3.8 and newer
## Installation
```bash
pip install git+https://github.com/pingcap/sqlalchemy-tidb.git@main
```
## Getting Started
In your Python app, you can connect to the database via:
```python
from sqlalchemy import create_engine
engine = create_engine("tidb://username:password@ip:port/database_name?charset=utf8mb4")
```
## Known issues
- TiDB only support `FOREIGN KEY` constraints since v6.6.0([#18209](https://github.com/pingcap/tidb/issues/18209)).
- TiDB only support `SAVEPOINT` since v6.2.0([#6840](https://github.com/pingcap/tidb/issues/6840)).
## Testing this dialect with SQLAlchemy and Alembic
Bootstrap your environment with virtualenv and requirements installed
```bash
make bootstrap
```
You can run the tests using the following command:
```bash
make all
# Or running test with `tox` for a specified python version
tox -e py39
# Or running test directly using `pytest`
pytest "test/test_suite.py::DateTest"
```
To know more about developing the TiDB dialect, checkout the guide on sqlalchemy:
* https://github.com/sqlalchemy/sqlalchemy/blob/rel_1_4/README.dialects.rst
* https://github.com/sqlalchemy/sqlalchemy/blob/rel_1_4/README.unittests.rst