Created
November 1, 2018 18:03
-
-
Save tonko22/40fe8823810d6cd681223a004cbfab01 to your computer and use it in GitHub Desktop.
Hello guys
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sqlalchemy.ext.declarative import declarative_base | |
from sqlalchemy import Column, Integer, String, Float, ForeignKey, DateTime | |
from clickhouse_sqlalchemy import Table, make_session, get_declarative_base, types, engines | |
from sqlalchemy.orm import relationship | |
from sqlalchemy import create_engine, Column, MetaData, literal | |
engine = create_engine('clickhouse://default:@127.0.0.1:8123/test_db') | |
session = make_session(engine) | |
metadata = MetaData(bind=engine) | |
Base = get_declarative_base(metadata=metadata) | |
class Parent(Base): | |
__tablename__ = 'parent' | |
id = Column(Integer, primary_key=True) | |
date = Column(types.Date) | |
time = Column(types.DateTime) | |
children = relationship("Child", back_populates="parent") | |
__table_args__ = ( | |
engines.MergeTree(date, (id,)), | |
) | |
class Child(Base): | |
__tablename__ = 'child' | |
id = Column(Integer, primary_key=True) | |
date = Column(types.Date) | |
time = Column(types.DateTime) | |
parent_id = Column(Integer, ForeignKey('parent.id')) | |
parent = relationship("Parent", back_populates="children") | |
__table_args__ = ( | |
engines.MergeTree(date, (id,)), | |
) | |
if __name__ == "__main__": | |
# engine = create_engine(db_connection.connection_string, echo=True) | |
# engine.connect() | |
# Base.metadata.drop_all(engine) | |
Base.metadata.create_all(engine) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment