35 lines
974 B
Python
35 lines
974 B
Python
__all__ = 'CK',
|
|
|
|
from datetime import datetime
|
|
from datetime import timedelta
|
|
|
|
from clickhouse_driver import Client
|
|
|
|
|
|
class CK(Client):
|
|
def __init__(self, *args, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
|
|
def get_one(self, db, tb, **where) -> dict:
|
|
"""
|
|
注意 还原时区
|
|
:param db:
|
|
:param tb:
|
|
:param where:
|
|
:return:
|
|
"""
|
|
sql = f"select * from {db}.{tb} where 1"
|
|
for k, v in where.items():
|
|
sql += f" and `{k}`='{v}'"
|
|
sql += ' limit 1'
|
|
data, columns = self.execute(sql, with_column_types=True)
|
|
res = dict()
|
|
if data:
|
|
data = {k[0]: v for k, v in zip(columns, data[0])}
|
|
for k, v in data.items():
|
|
if isinstance(v, datetime):
|
|
res[k] = (v + timedelta(hours=data['#zone_offset'])).strftime('%Y-%m-%d %H:%M:%S')
|
|
else:
|
|
res[k] = v
|
|
return res
|