From b7709126f9430a87bfcd515f4f37b6fa11e4f17c Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 16 Mar 2023 18:07:22 +0100 Subject: [PATCH] remove .query completely --- freqtrade/commands/db_commands.py | 8 ++++---- freqtrade/persistence/models.py | 3 --- freqtrade/persistence/pairlock.py | 3 +-- freqtrade/persistence/trade_model.py | 4 +--- 4 files changed, 6 insertions(+), 12 deletions(-) diff --git a/freqtrade/commands/db_commands.py b/freqtrade/commands/db_commands.py index c819ca243..d83605c6f 100644 --- a/freqtrade/commands/db_commands.py +++ b/freqtrade/commands/db_commands.py @@ -1,7 +1,7 @@ import logging from typing import Any, Dict -from sqlalchemy import func +from sqlalchemy import func, select from freqtrade.configuration.config_setup import setup_utils_configuration from freqtrade.enums import RunMode @@ -43,9 +43,9 @@ def start_convert_db(args: Dict[str, Any]) -> None: session_target.commit() # Update sequences - max_trade_id = session_target.query(func.max(Trade.id)).scalar() - max_order_id = session_target.query(func.max(Order.id)).scalar() - max_pairlock_id = session_target.query(func.max(PairLock.id)).scalar() + max_trade_id = session_target.scalar(select(func.max(Trade.id))) + max_order_id = session_target.scalar(select(func.max(Order.id))) + max_pairlock_id = session_target.scalar(select(func.max(PairLock.id))) set_sequence_ids(session_target.get_bind(), trade_id=max_trade_id, diff --git a/freqtrade/persistence/models.py b/freqtrade/persistence/models.py index f4058b4eb..eee07e61c 100644 --- a/freqtrade/persistence/models.py +++ b/freqtrade/persistence/models.py @@ -57,9 +57,6 @@ def init_db(db_url: str) -> None: Trade.session = scoped_session(sessionmaker(bind=engine, autoflush=False)) Order.session = Trade.session PairLock.session = Trade.session - Trade.query = Trade.session.query_property() - Order.query = Trade.session.query_property() - PairLock.query = Trade.session.query_property() previous_tables = inspect(engine).get_table_names() ModelBase.metadata.create_all(engine) diff --git a/freqtrade/persistence/pairlock.py b/freqtrade/persistence/pairlock.py index e787b5fa0..1b254c2b2 100644 --- a/freqtrade/persistence/pairlock.py +++ b/freqtrade/persistence/pairlock.py @@ -2,7 +2,7 @@ from datetime import datetime, timezone from typing import Any, ClassVar, Dict, Optional from sqlalchemy import ScalarResult, String, or_, select -from sqlalchemy.orm import Mapped, QueryPropertyDescriptor, mapped_column +from sqlalchemy.orm import Mapped, mapped_column from freqtrade.constants import DATETIME_PRINT_FORMAT from freqtrade.persistence.base import ModelBase, SessionType @@ -13,7 +13,6 @@ class PairLock(ModelBase): Pair Locks database model. """ __tablename__ = 'pairlocks' - query: ClassVar[QueryPropertyDescriptor] session: ClassVar[SessionType] id: Mapped[int] = mapped_column(primary_key=True) diff --git a/freqtrade/persistence/trade_model.py b/freqtrade/persistence/trade_model.py index 892707810..27be0d726 100644 --- a/freqtrade/persistence/trade_model.py +++ b/freqtrade/persistence/trade_model.py @@ -9,7 +9,7 @@ from typing import Any, ClassVar, Dict, List, Optional, Sequence, cast from sqlalchemy import (Enum, Float, ForeignKey, Integer, ScalarResult, Select, String, UniqueConstraint, desc, func, select) -from sqlalchemy.orm import Mapped, QueryPropertyDescriptor, lazyload, mapped_column, relationship +from sqlalchemy.orm import Mapped, lazyload, mapped_column, relationship from freqtrade.constants import (DATETIME_PRINT_FORMAT, MATH_CLOSE_PREC, NON_OPEN_EXCHANGE_STATES, BuySell, LongShort) @@ -36,7 +36,6 @@ class Order(ModelBase): Mirrors CCXT Order structure """ __tablename__ = 'orders' - query: ClassVar[QueryPropertyDescriptor] session: ClassVar[SessionType] # Uniqueness should be ensured over pair, order_id @@ -1188,7 +1187,6 @@ class Trade(ModelBase, LocalTrade): Note: Fields must be aligned with LocalTrade class """ __tablename__ = 'trades' - query: ClassVar[QueryPropertyDescriptor] session: ClassVar[SessionType] use_db: bool = True