from databases import Database import datetime def get_db_conn(config): db_url = f"{config.DB_URI}" return Database(db_url) class Repository: def __init__(self, db_conn): self.db_conn = db_conn async def get_by_query(self, query, param): results = await self.db_conn.fetch_all(query, param) print("result get _by query", results) return [dict(result) for result in results] async def _fetch_one(self, query, param): result = await self.db_conn.fetch_one(query, param) return dict(result) if result is not None else result async def _exec(self, query, param): return await self.db_conn.execute(query, param) async def _exec_many(self, query, params): return await self.db_conn.execute_many(query, params) def update_params(self, params, update=False): current_time = datetime.datetime.now() if update == False: params.update({"createdAt": current_time, "updatedAt": current_time}) else: params.update({"updatedAt": current_time}) return params