# Apache Doris Dialect for SQLAlchemy
This is a fork of [sqlalchemy-doris](https://github.com/actcwlf/sqlalchemy-doris) project.
Which is in turn - a fork of [pydoris](https://pypi.org/project/pydoris/1.0.1/)
This implementation fixes a bunch of issues with typing. And adds support for sqlalchemy ORM.
## Features
* support SQLAlchemy 2.
* support pymysql and mysqlclient as driver.
* support SQLAlchemy table creation
* support for SQLALchemy ORM
* convenient DorisBase class for declaring ORM models
## Installation
Use
```bash
pip install doris-alchemy[pymysql]
```
for pymysql.
Or
```bash
pip install doris-alchemy[mysqldb]
```
for mysqlclient.
Note doris-alchemy 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 (Imperative style)
```python
import sqlalchemy as sa
from sqlalchemy import create_engine
from doris_alchemy import datatype
from doris_alchemy import HASH, RANGE
engine = create_engine(f"doris://{user}:{password}@{host}:{port}/{database}?charset=utf8mb4")
metadata_obj = sa.MetaData()
table = Table(
'dummy_table',
METADATA,
Column('id', Integer, primary_key=True),
Column('name', String(64), nullable=False),
Column('description', Text),
Column('date', DateTime),
doris_unique_key=('id'),
doris_partition_by=RANGE('id'),
doris_distributed_by=HASH('id'),
doris_properties={"replication_allocation": "tag.location.default: 1"},
)
table.create(engine)
```
SQL is
```sql
CREATE TABLE dummy_table (
id INTEGER NOT NULL,
name VARCHAR(64) NOT NULL,
description TEXT,
date DATETIME
)
UNIQUE KEY (`id`)
PARTITION BY RANGE(`id`) ()
DISTRIBUTED BY HASH(`id`) BUCKETS auto
PROPERTIES (
"replication_allocation" = "tag.location.default: 1"
)
```
## Create Table (Declarative style / ORM)
```python
from sqlalchemy import create_engine
from doris_alchemy import datatype, DorisBase
from doris_alchemy import HASH, RANGE
engine = create_engine(f"doris://{user}:{password}@{host}:{port}/{database}?charset=utf8mb4")
class Dummy(DorisBase):
__tablename__ = 'dummy_two'
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
name: Mapped[str] = mapped_column(String(127))
description: Mapped[str]
date: Mapped[datetime]
__table_args__ = {
'doris_properties': {"replication_allocation": "tag.location.default: 1"}
}
doris_unique_key = 'id'
doris_distributed_by = HASH('id')
doris_partition_by = RANGE('id')
DorisBase.metadata.create_all(engine)
```
SQL is
```sql
CREATE TABLE dummy_two (
id BIGINT NOT NULL,
name VARCHAR(127) NOT NULL,
description TEXT NOT NULL,
date DATETIME NOT NULL
)
UNIQUE KEY (`id`)
PARTITION BY RANGE(`id`) ()
DISTRIBUTED BY HASH(`id`) BUCKETS auto
PROPERTIES (
"replication_allocation" = "tag.location.default: 1"
)
```
### Insertin and selecting
```python
from sqlalchemy.orm import Session
from sqlalchemy import select, insert, create_engine
from datetime import datetime
engine = create_engine(f"doris+mysqldb://{USER}:{PWD}@{HOST}:{PORT}/{DB}")
row = {
'id': 0,
'name': 'Airbus',
'description': 'Construction bureau',
'date': datetime(2024, 2, 10)
}
with Session(engine) as s:
q = insert(Dummy).values([row])
s.execute(q)
sel = select(Dummy)
res = s.execute(sel)
print(list(res))
```
Raw data
{
"_id": null,
"home_page": null,
"name": "doris-alchemy",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10.12",
"maintainer_email": "vtsiura <morfey.rulit@gmail.com>",
"keywords": "Apache Doris, SQLAlchemy",
"author": null,
"author_email": "vtsiura <morfey.rulit@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/80/95/fed41f58ef2547da412dd1d429d88cba1ad530fc38e5af0c9efc1d62f35d/doris_alchemy-0.2.5.tar.gz",
"platform": null,
"description": "# Apache Doris Dialect for SQLAlchemy\n\nThis is a fork of [sqlalchemy-doris](https://github.com/actcwlf/sqlalchemy-doris) project.\nWhich is in turn - a fork of [pydoris](https://pypi.org/project/pydoris/1.0.1/)\n\nThis implementation fixes a bunch of issues with typing. And adds support for sqlalchemy ORM.\n\n## Features\n* support SQLAlchemy 2.\n* support pymysql and mysqlclient as driver.\n* support SQLAlchemy table creation\n* support for SQLALchemy ORM\n* convenient DorisBase class for declaring ORM models\n\n## Installation\nUse\n```bash\npip install doris-alchemy[pymysql]\n```\nfor pymysql.\n\nOr\n\n```bash\npip install doris-alchemy[mysqldb]\n```\nfor mysqlclient.\n\nNote doris-alchemy uses pymysql as default connector for compatibility. \nIf both pymysql and mysqlclient are installed, mysqlclient is preferred.\n\n\n## Usage\n```python\n\nfrom sqlalchemy import create_engine\n\nengine = create_engine(f\"doris+pymysql://{user}:{password}@{host}:{port}/{database}?charset=utf8mb4\")\n# or\nengine = create_engine(f\"doris+mysqldb://{user}:{password}@{host}:{port}/{database}?charset=utf8mb4\")\n\n```\n\n## Create Table (Imperative style)\n```python\nimport sqlalchemy as sa\nfrom sqlalchemy import create_engine\nfrom doris_alchemy import datatype\nfrom doris_alchemy import HASH, RANGE\n\nengine = create_engine(f\"doris://{user}:{password}@{host}:{port}/{database}?charset=utf8mb4\")\n\n\nmetadata_obj = sa.MetaData()\ntable = Table(\n 'dummy_table',\n METADATA,\n Column('id', Integer, primary_key=True),\n Column('name', String(64), nullable=False),\n Column('description', Text),\n Column('date', DateTime),\n \n doris_unique_key=('id'),\n doris_partition_by=RANGE('id'),\n doris_distributed_by=HASH('id'),\n doris_properties={\"replication_allocation\": \"tag.location.default: 1\"},\n)\n\ntable.create(engine)\n\n```\n\nSQL is\n```sql\nCREATE TABLE dummy_table (\n id INTEGER NOT NULL, \n name VARCHAR(64) NOT NULL, \n description TEXT, \n date DATETIME\n)\nUNIQUE KEY (`id`)\nPARTITION BY RANGE(`id`) ()\nDISTRIBUTED BY HASH(`id`) BUCKETS auto\nPROPERTIES (\n \"replication_allocation\" = \"tag.location.default: 1\"\n)\n```\n\n## Create Table (Declarative style / ORM)\n```python\nfrom sqlalchemy import create_engine\nfrom doris_alchemy import datatype, DorisBase\nfrom doris_alchemy import HASH, RANGE\n\nengine = create_engine(f\"doris://{user}:{password}@{host}:{port}/{database}?charset=utf8mb4\")\n\nclass Dummy(DorisBase):\n __tablename__ = 'dummy_two'\n \n id: Mapped[int] = mapped_column(BigInteger, primary_key=True)\n name: Mapped[str] = mapped_column(String(127))\n description: Mapped[str]\n date: Mapped[datetime]\n \n __table_args__ = {\n 'doris_properties': {\"replication_allocation\": \"tag.location.default: 1\"}\n }\n doris_unique_key = 'id'\n doris_distributed_by = HASH('id')\n doris_partition_by = RANGE('id')\n\n\nDorisBase.metadata.create_all(engine)\n```\nSQL is \n```sql\nCREATE TABLE dummy_two (\n id BIGINT NOT NULL, \n name VARCHAR(127) NOT NULL, \n description TEXT NOT NULL, \n date DATETIME NOT NULL\n)\nUNIQUE KEY (`id`)\nPARTITION BY RANGE(`id`) ()\nDISTRIBUTED BY HASH(`id`) BUCKETS auto\nPROPERTIES (\n \"replication_allocation\" = \"tag.location.default: 1\"\n)\n```\n\n### Insertin and selecting\n\n```python\nfrom sqlalchemy.orm import Session\nfrom sqlalchemy import select, insert, create_engine\nfrom datetime import datetime\n\nengine = create_engine(f\"doris+mysqldb://{USER}:{PWD}@{HOST}:{PORT}/{DB}\")\n\nrow = {\n 'id': 0,\n 'name': 'Airbus',\n 'description': 'Construction bureau',\n 'date': datetime(2024, 2, 10)\n }\n \nwith Session(engine) as s:\n q = insert(Dummy).values([row])\n s.execute(q)\n sel = select(Dummy)\n res = s.execute(sel)\n print(list(res))\n```\n",
"bugtrack_url": null,
"license": "Apache Software License",
"summary": "Apache Doris dialect for SQLAlchemy",
"version": "0.2.5",
"project_urls": {
"Homepage": "https://github.com/VasilevsVV/doris-alchemy",
"Issues": "https://github.com/VasilevsVV/doris-alchemy/issues"
},
"split_keywords": [
"apache doris",
" sqlalchemy"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "77da7cc08aaff26f194fa5db4492f3975f015841c513c40c73caa8e1571f8925",
"md5": "86c79a7bc967d7117b0af430abc33924",
"sha256": "d03af63aaa2e3fb9e80381524c3aabaae992382bed71db33ef16c4223c153938"
},
"downloads": -1,
"filename": "doris_alchemy-0.2.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "86c79a7bc967d7117b0af430abc33924",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10.12",
"size": 17515,
"upload_time": "2024-12-20T13:42:36",
"upload_time_iso_8601": "2024-12-20T13:42:36.315833Z",
"url": "https://files.pythonhosted.org/packages/77/da/7cc08aaff26f194fa5db4492f3975f015841c513c40c73caa8e1571f8925/doris_alchemy-0.2.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "8095fed41f58ef2547da412dd1d429d88cba1ad530fc38e5af0c9efc1d62f35d",
"md5": "97713f77ebc310be8d1a7efce8886770",
"sha256": "c60b5b008863d90b4d5c74300f832b9c347402f8932d93e837db2bfe4c297e02"
},
"downloads": -1,
"filename": "doris_alchemy-0.2.5.tar.gz",
"has_sig": false,
"md5_digest": "97713f77ebc310be8d1a7efce8886770",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10.12",
"size": 18606,
"upload_time": "2024-12-20T13:42:40",
"upload_time_iso_8601": "2024-12-20T13:42:40.290880Z",
"url": "https://files.pythonhosted.org/packages/80/95/fed41f58ef2547da412dd1d429d88cba1ad530fc38e5af0c9efc1d62f35d/doris_alchemy-0.2.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-20 13:42:40",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "VasilevsVV",
"github_project": "doris-alchemy",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"tox": true,
"lcname": "doris-alchemy"
}