From 0ac499ae8c05a0496e8ee51ffd0291e042ea527d Mon Sep 17 00:00:00 2001 From: "Bobby (aider)" Date: Tue, 11 Feb 2025 18:15:54 -0800 Subject: [PATCH] refactor: Update database client methods to use `command` and `query` for SQL execution --- src/trading/trading_plan.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/trading/trading_plan.py b/src/trading/trading_plan.py index a741d48..931dc8b 100644 --- a/src/trading/trading_plan.py +++ b/src/trading/trading_plan.py @@ -79,7 +79,7 @@ def create_trading_plan_table(): with create_client() as client: try: # Drop the table if it exists to ensure a clean creation - client.execute("DROP TABLE IF EXISTS trading_plans") + client.command("DROP TABLE IF EXISTS trading_plans") # Create new table with a simple structure query = """ @@ -125,7 +125,7 @@ def create_trading_plan_table(): ) ENGINE = TinyLog """ - client.execute(query) + client.command(query) print("Table 'trading_plans' created successfully.") except Exception as e: @@ -136,7 +136,7 @@ def save_trading_plan(plan: TradingPlan) -> int: with create_client() as client: if not plan.id: # Generate new ID for new plans - result = client.execute("SELECT max(id) FROM trading_plans") + result = client.query("SELECT max(id) FROM trading_plans") plan.id = (result[0][0] or 0) + 1 plan.created_at = datetime.now() @@ -198,13 +198,13 @@ def save_trading_plan(plan: TradingPlan) -> int: 'options_strategy_details': plan.options_strategy_details } - client.execute(query, params) + client.command(query, params) return plan.id def get_trading_plan(plan_id: int) -> Optional[TradingPlan]: """Get a trading plan by ID""" with create_client() as client: - result = client.execute(""" + result = client.query(""" SELECT * FROM trading_plans WHERE id = %(id)s """, {'id': plan_id}) @@ -265,7 +265,7 @@ def get_all_trading_plans(status: Optional[PlanStatus] = None) -> List[TradingPl query += " ORDER BY updated_at DESC" - results = client.execute(query, params) + results = client.query(query, params) return [get_trading_plan(result[0]) for result in results] except Exception as e: @@ -360,5 +360,5 @@ def update_trading_plan(plan: TradingPlan) -> bool: 'options_strategy_details': plan.options_strategy_details } - client.execute(query, params) + client.command(query, params) return True