Skip to content

Commit

Permalink
Run everything in a transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Jan 24, 2024
1 parent 7a34bb1 commit 4c19d5e
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions datasette_upload_csvs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,19 +159,20 @@ def docs_with_progress():
"completed": str(datetime.datetime.utcnow()),
},
)
# Trasform columns to detected types
# Transform columns to detected types
database[table_name].transform(types=tracker.types)
return database[table_name].count

def insert_docs_catch_errors(conn):
database = sqlite_utils.Database(conn)
try:
insert_docs(database)
except Exception as error:
database["_csv_progress_"].update(
task_id,
{"error": str(error)},
)
with conn:
try:
insert_docs(database)
except Exception as error:
database["_csv_progress_"].update(
task_id,
{"error": str(error)},
)

await db.execute_write_fn(insert_docs_catch_errors, block=False)

Expand Down

0 comments on commit 4c19d5e

Please sign in to comment.