doris-alchemy


Namedoris-alchemy JSON
Version 0.2.3 PyPI version JSON
download
home_pageNone
SummaryApache Doris dialect for SQLAlchemy
upload_time2024-08-22 13:32:00
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10.12
licenseApache Software License
keywords apache doris sqlalchemy
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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/d3/78/e682be8e7081232e5d645b56645b1269f319aaf0fda889c59dc063bd1665/doris_alchemy-0.2.3.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.3",
    "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": "a087fb9d63b67465acb06c62927f1b710db8ccf34d3182b235269fc1d73fe53c",
                "md5": "137809257b198cdf38852f4ed621b0fe",
                "sha256": "0a58adcf098ec40304f6e1832ed1abb47fb49d7c890df6da8985b6045ce8a43f"
            },
            "downloads": -1,
            "filename": "doris_alchemy-0.2.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "137809257b198cdf38852f4ed621b0fe",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10.12",
            "size": 18332,
            "upload_time": "2024-08-22T13:31:58",
            "upload_time_iso_8601": "2024-08-22T13:31:58.791890Z",
            "url": "https://files.pythonhosted.org/packages/a0/87/fb9d63b67465acb06c62927f1b710db8ccf34d3182b235269fc1d73fe53c/doris_alchemy-0.2.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d378e682be8e7081232e5d645b56645b1269f319aaf0fda889c59dc063bd1665",
                "md5": "e10dd9c4f058aa94982a17c9b23f210a",
                "sha256": "a4cadb3191d1c9db1a1ca435daab7743ebe4a2947f2efc906003142fe4414c59"
            },
            "downloads": -1,
            "filename": "doris_alchemy-0.2.3.tar.gz",
            "has_sig": false,
            "md5_digest": "e10dd9c4f058aa94982a17c9b23f210a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10.12",
            "size": 19191,
            "upload_time": "2024-08-22T13:32:00",
            "upload_time_iso_8601": "2024-08-22T13:32:00.502211Z",
            "url": "https://files.pythonhosted.org/packages/d3/78/e682be8e7081232e5d645b56645b1269f319aaf0fda889c59dc063bd1665/doris_alchemy-0.2.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-22 13:32:00",
    "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"
}
        
Elapsed time: 0.44309s