Git Product home page Git Product logo

clickhouse-sqlalchemy's Introduction

ClickHouse SQLAlchemy

ClickHouse dialect for SQLAlchemy to ClickHouse database.

https://coveralls.io/repos/github/xzkostyan/clickhouse-sqlalchemy/badge.svg?branch=master

Documentation

Documentation is available at https://clickhouse-sqlalchemy.readthedocs.io.

Usage

Supported interfaces:

Define table

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(),
    )

Rate.__table__.create()

Insert some data

from datetime import date, timedelta

from sqlalchemy import func

today = date.today()
rates = [
    {'day': today - timedelta(i), 'value': 200 - i}
    for i in range(100)
]

And query inserted data

session.execute(Rate.__table__.insert(), rates)

session.query(func.count(Rate.day)) \
    .filter(Rate.day > today - timedelta(20)) \
    .scalar()

License

ClickHouse SQLAlchemy is distributed under the MIT license.

clickhouse-sqlalchemy's People

Contributors

xzkostyan avatar hhell avatar carlosefr avatar dentaku7 avatar ods avatar achilleash avatar skorpyon avatar antonfriberg avatar armymaksim avatar khvn26 avatar ei-grad avatar aamalev avatar vanchaxy avatar nikitka avatar berdoc avatar vanzi avatar hodgesrm avatar reflection avatar teddycr avatar vmarkovtsev avatar howbownotnow avatar yhvicey avatar bolshakovno avatar joelynch avatar rrockru avatar save-my-heart avatar lance0805 avatar joozty avatar athre0z avatar wlhjason avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.