#!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2023/4/8 10:12 # @Author : old tom # @File : fu_dao.py # @Project : futool-tiny-datahub # @Desc : 通用dao层 from collections import namedtuple from common.fudb.connectors.connector_factory import ConnFactory from common.fudb.dbapis.fu_db_api import select_all, select_one, batch_insert, count, execute_update class BaseDao(object): def __init__(self, connector: ConnFactory): self.connector = connector def query_all(self, sql): return select_all(self.connector.get_conn(), sql) def query_one(self, sql): return select_one(self.connector.get_conn(), sql) def count(self, table_name): return count(self.connector.get_conn(), table_name) def execute_update(self, sql): return execute_update(self.connector.get_conn(), sql) def batch_insert(self, db_type, sql_tpl, data, batch_size): return batch_insert(self.connector.get_conn(), db_type, sql_tpl, data, batch_size) def dynamic_update_by_param(self, table_name, condition, param: dict): """ 动态更新语句 :param condition: :param table_name: 表名 :param param: 命名元组参数 :return: """ sql = f'update {table_name} set ' for k, v in param.items(): sql += f'{k}=' + (f"'{v}'" if isinstance(v, str) else f'{v}') + "," sql = sql[0: -1] sql += f' where {condition}' return self.execute_update(sql)