Skip to content

actcwlf/sqlalchemy-doris

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Apache Doris Dialect for SQLAlchemy

This is an unofficial implementation forked from pydoris

Features

  • support SQLAlchemy 2.
  • support pymysql and mysqlclient as driver.
  • support SQLAlchemy table creation

Installation

Use

pip install sqlalchemy-doris[pymysql]

for pymysql.

Or

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

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

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

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"
)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages