diff --git a/src/helpers/database.py b/src/helpers/database.py index a97c6b8..a3c4bd1 100644 --- a/src/helpers/database.py +++ b/src/helpers/database.py @@ -212,22 +212,16 @@ def write_token_decimals(self, token_decimals: list[tuple[str, int]]) -> None: # Define the table without creating a model class token_decimals_table = Table( - "token_decimals", - MetaData(), - Column("token_address", LargeBinary, primary_key=True), - Column("decimals", Integer, nullable=False), + "token_decimals", MetaData(), autoload_with=self.engine ) # Prepare the data - values = [ + records = [ {"token_address": bytes.fromhex(token_address[2:]), "decimals": decimals} for token_address, decimals in token_decimals ] - # Create the insert statement - stmt = insert(token_decimals_table).values(values) - # Execute the bulk insert with self.engine.connect() as conn: - conn.execute(stmt) + conn.execute(token_decimals_table.insert(), records) conn.commit() diff --git a/tests/unit/test_database.py b/tests/unit/test_database.py index 90b3ff0..18d1302 100644 --- a/tests/unit/test_database.py +++ b/tests/unit/test_database.py @@ -8,7 +8,7 @@ def tests_write_transaction_timestamp(): engine = create_engine( - f"postgresql+psycopg://postgres:postgres@localhost:5432/mainnet" + "postgresql+psycopg://postgres:postgres@localhost:5432/mainnet" ) db = Database(engine, "mainnet") # truncate table