mirror of
https://github.com/hanzo-ds/connect.git
synced 2026-10-30 20:31:24 +00:00
* migrate from pylint to ruff * ruff format/lint switch over * add formatting commit * update changelog
55 lines
1.3 KiB
Python
55 lines
1.3 KiB
Python
from clickhouse_connect.dbapi.cursor import Cursor
|
|
from clickhouse_connect.driver import create_client
|
|
from clickhouse_connect.driver.query import QueryResult
|
|
|
|
|
|
class Connection:
|
|
"""
|
|
See :ref:`https://peps.python.org/pep-0249/`
|
|
"""
|
|
|
|
def __init__(
|
|
self,
|
|
dsn: str = None,
|
|
username: str = "",
|
|
password: str = "",
|
|
host: str = None,
|
|
database: str = None,
|
|
interface: str = None,
|
|
port: int = 0,
|
|
secure: bool | str = False,
|
|
**kwargs,
|
|
):
|
|
self.client = create_client(
|
|
host=host,
|
|
username=username,
|
|
password=password,
|
|
database=database,
|
|
interface=interface,
|
|
port=port,
|
|
secure=secure,
|
|
dsn=dsn,
|
|
generic_args=kwargs,
|
|
)
|
|
|
|
self.client._add_integration_tag("sqlalchemy")
|
|
self.timezone = self.client.server_tz
|
|
|
|
def close(self):
|
|
self.client.close()
|
|
|
|
def commit(self):
|
|
pass
|
|
|
|
def rollback(self):
|
|
pass
|
|
|
|
def command(self, cmd: str):
|
|
return self.client.command(cmd)
|
|
|
|
def raw_query(self, query: str) -> QueryResult:
|
|
return self.client.query(query)
|
|
|
|
def cursor(self):
|
|
return Cursor(self.client)
|