# Apache Doris Dialect for SQLAlchemy
This is an unofficial implementation forked from [pydoris](https://pypi.org/project/pydoris/1.0.1/)
## Features
* support SQLAlchemy 2.
* support pymysql and mysqlclient as driver.
* support SQLAlchemy table creation
## Installation
Use
```bash
pip install sqlalchemy-doris[pymysql]
```
for pymysql.
Or
```bash
pip install sqlalchemy-doris[mysqldb]
```
for mysqlclient.
Note sqlalchemy-doris uses pymysql as default connector for compatibility.
If both pymysql and mysqlclient are installed, mysqlclient is preferred.
## Usage
```python
from sqlalchemy import create_engine
engine = create_engine(f"doris+pymysql://{user}:{password}@{host}:{port}/{database}?charset=utf8mb4")
# or
engine = create_engine(f"doris+mysqldb://{user}:{password}@{host}:{port}/{database}?charset=utf8mb4")
```
### Create Table
```python
import sqlalchemy as sa
from sqlalchemy import create_engine
from sqlalchemy_doris import datatype
from sqlalchemy_doris import HASH, RANGE
engine = create_engine(f"doris://{user}:{password}@{host}:{port}/{database}?charset=utf8mb4")
metadata_obj = sa.MetaData()
table_obj = sa.Table(
'test_table',
metadata_obj,
sa.Column("id", datatype.Integer),
doris_unique_key=('id', ),
doris_partition_by=RANGE('id'),
doris_distributed_by=HASH('id'),
doris_properties={"replication_allocation": "tag.location.default: 1"}
)
metadata_obj.create_all(engine)
```
SQL is
```sql
CREATE TABLE test_table (
id INTEGER
)
UNIQUE KEY (`id`)
PARTITION BY RANGE(`id`) ()
DISTRIBUTED BY HASH(`id`) BUCKETS auto
PROPERTIES (
"replication_allocation" = "tag.location.default: 1"
)
```
Raw data
{
"_id": null,
"home_page": "",
"name": "sqlalchemy-doris",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "Apache Doris,SQLAlchemy",
"author": "",
"author_email": "actcwlf <actcwlf@qq.com>",
"download_url": "",
"platform": null,
"description": "# Apache Doris Dialect for SQLAlchemy\r\n\r\nThis is an unofficial implementation forked from [pydoris](https://pypi.org/project/pydoris/1.0.1/)\r\n\r\n## Features\r\n* support SQLAlchemy 2.\r\n* support pymysql and mysqlclient as driver.\r\n* support SQLAlchemy table creation\r\n\r\n## Installation\r\nUse\r\n```bash\r\npip install sqlalchemy-doris[pymysql]\r\n```\r\nfor pymysql.\r\n\r\nOr\r\n\r\n```bash\r\npip install sqlalchemy-doris[mysqldb]\r\n```\r\nfor mysqlclient.\r\n\r\nNote sqlalchemy-doris uses pymysql as default connector for compatibility. \r\nIf both pymysql and mysqlclient are installed, mysqlclient is preferred.\r\n\r\n\r\n## Usage\r\n```python\r\n\r\nfrom sqlalchemy import create_engine\r\n\r\nengine = create_engine(f\"doris+pymysql://{user}:{password}@{host}:{port}/{database}?charset=utf8mb4\")\r\n# or\r\nengine = create_engine(f\"doris+mysqldb://{user}:{password}@{host}:{port}/{database}?charset=utf8mb4\")\r\n\r\n```\r\n\r\n### Create Table\r\n```python\r\nimport sqlalchemy as sa\r\nfrom sqlalchemy import create_engine\r\nfrom sqlalchemy_doris import datatype\r\nfrom sqlalchemy_doris import HASH, RANGE\r\n\r\nengine = create_engine(f\"doris://{user}:{password}@{host}:{port}/{database}?charset=utf8mb4\")\r\n\r\n\r\nmetadata_obj = sa.MetaData()\r\ntable_obj = sa.Table(\r\n 'test_table',\r\n metadata_obj,\r\n sa.Column(\"id\", datatype.Integer),\r\n doris_unique_key=('id', ),\r\n doris_partition_by=RANGE('id'),\r\n doris_distributed_by=HASH('id'),\r\n doris_properties={\"replication_allocation\": \"tag.location.default: 1\"}\r\n)\r\n\r\nmetadata_obj.create_all(engine)\r\n\r\n```\r\n\r\nSQL is\r\n```sql\r\nCREATE TABLE test_table (\r\n\tid INTEGER\r\n)\r\nUNIQUE KEY (`id`)\r\nPARTITION BY RANGE(`id`) ()\r\nDISTRIBUTED BY HASH(`id`) BUCKETS auto\r\nPROPERTIES (\r\n \"replication_allocation\" = \"tag.location.default: 1\"\r\n)\r\n```\r\n",
"bugtrack_url": null,
"license": "Apache Software License",
"summary": "Apache Doris dialect for SQLAlchemy",
"version": "0.2.1",
"project_urls": {
"Homepage": "https://github.com/actcwlf/sqlalchemy-doris",
"Issues": "https://github.com/actcwlf/sqlalchemy-doris/issues"
},
"split_keywords": [
"apache doris",
"sqlalchemy"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "930e88aa88c55cba88364065e6c3cb4574883e8a5547203711bfc1787a65d09a",
"md5": "ccbe3757a258d5317ddbb443a220ebe9",
"sha256": "8934d2804ff3548ca6d07fa78b86d83c76786d0c8536d1affabb9b681a1b11c2"
},
"downloads": -1,
"filename": "sqlalchemy_doris-0.2.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ccbe3757a258d5317ddbb443a220ebe9",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 13515,
"upload_time": "2023-12-17T04:41:19",
"upload_time_iso_8601": "2023-12-17T04:41:19.226327Z",
"url": "https://files.pythonhosted.org/packages/93/0e/88aa88c55cba88364065e6c3cb4574883e8a5547203711bfc1787a65d09a/sqlalchemy_doris-0.2.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-12-17 04:41:19",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "actcwlf",
"github_project": "sqlalchemy-doris",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"tox": true,
"lcname": "sqlalchemy-doris"
}