Spaces:
Running
Running
File size: 823 Bytes
87444a0 acde124 87444a0 acde124 87444a0 acde124 87444a0 acde124 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
import clickhouse_connect
from src.agents.database.config import Config
_client = None
def _create_client():
return clickhouse_connect.get_client(
host=Config.CLICKHOUSE_HOST,
port=Config.CLICKHOUSE_PORT,
username=Config.CLICKHOUSE_USER,
password=Config.CLICKHOUSE_PASSWORD,
database=Config.CLICKHOUSE_DATABASE
)
def get_client():
global _client
if _client is None:
_client = _create_client()
return _client
def try_get_client():
try:
return get_client()
except Exception:
return None
def is_database_available() -> bool:
try:
client = get_client()
client.query("SELECT 1")
return True
except Exception:
return False
def execute_query(query: str):
return get_client().query(query)
|