基础
https://blog.csdn.net/yangxiaodong88/article/details/86494125
本篇文章已经讲解了怎么基础使用tormysql 异步客户端去操作mysql
封装前的demo
主要是在 db_base 里面对增删
demo 获取集合的sql
@classmethod
async def get_10(cls):
async with await pool.Connection() as conn:
async with conn.cursor() as cursor:
data = dict()
data["state"] = 1
data["approval_state"] = 3
data["parent_id"] = "NULL"
dd = ["4eb1c040f14111e8870c509a4c9436be", "d5fe1550f13a11e8ab55509a4c9436be"]
data["situation_id"] = tuple(dd)
# sql = "SELECT id,created_at,content FROM comment where state={state} and approval_state !='{approval_state}' and parent_id IS NULL and situation_id in {situation_id}"
sql = "SELECT id,created_at,content FROM comment where state={state} and approval_state !='{approval_state}' and parent_id IS {parent_id} and situation_id in {situation_id}"
# sql = "SELECT id,created_at,content FROM comment WHERE parent_id is NULL "
sql = sql.format(**data)
await cursor.execute(sql)
data = cursor.fetchall()
return data
@classmethod
async def get(cls):
async with await pool.Connection() as conn:
async with conn.cursor() as cursor:
# data = dict()
# data["db_name"] = "configuration"
# data["timestamp"] = "timestamp"
# data["identity"] = "identity"
# sql = "SELECT {timestamp},{identity} FROM {db_name} "
# sql = sql.format(**data)
# await cursor.execute(sql)
# data = cursor.fetchone()
data = dict()
data["db_name"] = "configuration"
data["aa"] = "timestamp" + "," + "identity"
# field_list = ["timestamp", "identity"] # ok
# field_list = ["*"] # ok
field_list = ["timestamp as tt", "identity"] # ok
field_list = ["sum(threshold) as thr"] # ok 可以有哈哈
field_list = ["identity", "threshold"] # ok 可以有哈哈
data["field"] = ",".join(field_list)
# condition = "threshold >100" # 可行
condition = "threshold >100 order by threshold desc" # 可行 perfect
condition = "id in(1,3,4)" # ok
condition = "description in('信誉积分下限')" # 真棒
# ======
# ids = [1, 3, 5]
# ids = tuple(ids)
# condition = "id in {ids}".format(ids=ids) # 真棒
###======= 可行
# a = 1, 2, 3 # 这种可以
a = [1, 3, 5]
# ids = [1]
# ids = ",".join(ids)
# ids = tuple(ids)
# ids = (1) # 这个不可以
# condition = "id in {ids}".format(ids=ids) # 真棒
# condition = "id in (1)" # 真棒 这个可以
# condition = "id in {ids}".format(ids=ids) # 真棒 这个可以
# condition = "id in {ids}".format(ids=a) # 真棒 这个可以
def get_in_data(data_):
if isinstance(data_