clickhouse-sqlalchemy icon indicating copy to clipboard operation
clickhouse-sqlalchemy copied to clipboard

chore(docs): Fix quick start example

Open franz101 opened this issue 1 year ago • 5 comments

The current example leads to the following error with sqlalchemy > 2: TypeError: MetaData.__init__() got an unexpected keyword argument 'bind'

Maybe fixes this: https://github.com/xzkostyan/clickhouse-sqlalchemy/issues/261

franz101 avatar Jan 24 '24 06:01 franz101

@xzkostyan do you mind adding me as a maintainer or we find a way to get small improvements through?

franz101 avatar Feb 14 '24 20:02 franz101

Let's start with a little PR review.

Why we use pure functions instead clickhouse-dialect wrappers here?

It seems that transferring bind=engine from MetaData to .create() call is only related change in this PR. What other changes are about?

It will not fix #261. For some reasons sqlalchemy_utils are used there.

xzkostyan avatar Feb 17 '24 19:02 xzkostyan

I see what you mean, thanks for the feedback:



engine = create_engine(uri)

# Base = get_declarative_base(metadata=metadata)

# Create a session.
Session = sessionmaker(bind=engine)
session = Session()
metadata = MetaData()
metadata.reflect(bind=engine)

# Define the base class using the declarative base.
Base = declarative_base(metadata=metadata)

this should reflect the metadata part?

Can you explain the difference between clickhouse dialect wrappers?

franz101 avatar Feb 26 '24 20:02 franz101

In general I was assuming clickhouse 2.0 was breaking the docs

franz101 avatar Feb 26 '24 20:02 franz101

This seems to work for now:

metadata = MetaData()
metadata.reflect(bind=engine)

Base = get_declarative_base(metadata=metadata)

franz101 avatar Feb 26 '24 23:02 franz101