Skip to content

Commit

Permalink
simplify token decimals writing setup
Browse files Browse the repository at this point in the history
  • Loading branch information
fhenneke committed Oct 11, 2024
1 parent 3f493a2 commit 44aa063
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
12 changes: 3 additions & 9 deletions src/helpers/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
2 changes: 1 addition & 1 deletion tests/unit/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 44aa063

Please sign in to comment.