Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(docs): Fix quick start example #289

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,34 @@ Define table
.. code-block:: python

from sqlalchemy import create_engine, Column, MetaData

from clickhouse_sqlalchemy import (
Table, make_session, get_declarative_base, types, engines
)

from sqlalchemy.orm import declarative_base, sessionmaker

from clickhouse_sqlalchemy import types, engines

uri = 'clickhouse+native://localhost/default'


# Create an engine.
engine = create_engine(uri)
session = make_session(engine)
metadata = MetaData(bind=engine)

Base = get_declarative_base(metadata=metadata)


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

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

class Rate(Base):
__tablename__ = 'rate'
day = Column(types.Date, primary_key=True)
value = Column(types.Int32)

__table_args__ = (
engines.Memory(),
)

# Create the table.
Rate.__table__.create(bind=engine)

Rate.__table__.create()


Insert some data
Expand Down
20 changes: 9 additions & 11 deletions docs/features.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,26 @@ Both declarative and constructor-style tables supported:

.. code-block:: python

from sqlalchemy import create_engine, Column, MetaData, literal

from sqlalchemy import create_engine, Column, MetaData
from clickhouse_sqlalchemy import (
Table, make_session, get_declarative_base, types, engines
)

uri = 'clickhouse://default:@localhost/test'

uri = 'clickhouse+native://localhost/default'
engine = create_engine(uri)
session = make_session(engine)
metadata = MetaData(bind=engine)

Base = get_declarative_base(metadata=metadata)

class Rate(Base):
day = Column(types.Date, primary_key=True)
value = Column(types.Int32, comment='Rate value')
other_value = Column(types.DateTime)

value = Column(types.Int32)

__table_args__ = (
engines.Memory(),
{'comment': 'Store rates'}
)

another_table = Table('another_rate', metadata,
Expand Down
16 changes: 8 additions & 8 deletions docs/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,27 @@ Let's define some table, insert data into it and query inserted data.
.. code-block:: python

from sqlalchemy import create_engine, Column, MetaData

from clickhouse_sqlalchemy import (
Table, make_session, get_declarative_base, types, engines
)

uri = 'clickhouse+native://localhost/default'

engine = create_engine(uri)
session = make_session(engine)
metadata = MetaData(bind=engine)

Base = get_declarative_base(metadata=metadata)

class Rate(Base):
day = Column(types.Date, primary_key=True)
value = Column(types.Int32)

__table_args__ = (
engines.Memory(),
)

# Emits CREATE TABLE statement
Rate.__table__.create()

Expand Down Expand Up @@ -69,4 +69,4 @@ Let's query inserted data
.scalar()

Now you are ready to :ref:`configure your connection<connection>` and see more
ClickHouse :ref:`features<features>` support.
ClickHouse :ref:`features<features>` support.