Skip to content

Commit

Permalink
no more pandas sql as it is not async
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianTremblay committed Aug 27, 2024
1 parent 131e589 commit e460fe8
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions BAC0/db/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
sql.py -
"""

import contextlib
import os.path

# --- standard Python modules ---
Expand All @@ -20,7 +19,6 @@
try:
import pandas as pd
from pandas.errors import DataError
from pandas.io import sql

try:
from pandas import Timestamp
Expand Down Expand Up @@ -228,13 +226,15 @@ def _df_to_backup():
# DataFrames that will be saved to SQL
async with aiosqlite.connect(f"{self.properties.db_name}.db") as con:
try:
data = pd.read_sql("SELECT * FROM history", con)
df = pd.concat([data, df_to_backup], sort=True)
async with con.execute("SELECT * FROM history") as cursor:
data = await cursor.fetchall()
columns = [description[0] for description in cursor.description]
data = pd.DataFrame(data, columns=columns)
df = pd.concat([data, df_to_backup], sort=True)
except Exception:
df = df_to_backup

sql.to_sql(
df_to_backup,
await df_to_backup.to_sql(
name="history",
con=con,
index_label="index",
Expand Down

0 comments on commit e460fe8

Please sign in to comment.