#๐ fastapi implement connection pool
11 messages ยท Page 1 of 1 (latest)
@swift kelp
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
# ClickHouse client
clickhouse_client = ClickhouseClient(host='120.120.1.51', port='9000', database='default', user='default', password='')
async_execute = asyncer.asyncify(clickhouse_client.execute)
async def get_total_alert_count(start_time: str, end_time: str) -> int:
# Format and sanitize date/time parameters
start_time = datetime.strptime(start_time, "%Y-%m-%d %H:%M:%S").strftime("%Y-%m-%d %H:%M:%S")
end_time = datetime.strptime(end_time, "%Y-%m-%d %H:%M:%S").strftime("%Y-%m-%d %H:%M:%S")
query = """
SELECT count(*) AS total_count
FROM suricata_d
WHERE
alert.signature_id >= 1
AND parseDateTimeBestEffort("timestamp", 'Asia/Karachi') >= parseDateTimeBestEffort('%(start_time)s', 'Asia/Karachi')
AND parseDateTimeBestEffort("timestamp", 'Asia/Karachi') <= parseDateTimeBestEffort('%(end_time)s', 'Asia/Karachi')
"""
params = {
'start_time': start_time,
'end_time': end_time,
}
# Print the final query with parameters substituted (for debugging purposes)
final_query = query % params
print("Final Query:", final_query)
try:
data = await async_execute(final_query, with_column_types=True)```
@full moth
need some help regarding this is how i create client and called using async_execute = asyncer.asyncify(clickhouse_client.execute)
as this my code need to handle request queries simulatenoly how to implement the connection pool to handle this
can you please guide
hello @full moth
๐ฆ
then i call like this data = await async_execute(final_query)
@swift kelp
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.