Skip to content

Commit

Permalink
Add utils functions to import and export DuckDB DBs
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacCheng9 committed Dec 25, 2023
1 parent fc04ddd commit 56cdb96
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
14 changes: 14 additions & 0 deletions utils/export_duckdb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"""
Export the DuckDB database schema and data to a directory to be imported later
by the user. This is preferred over version controlling the DB file itself
due to merge conflicts and other issues that arise with binary files.
"""
import duckdb

# The directory to get the DB file from.
export_from = "resources/portfolio.db"
# The directory to export the DB to.
export_to = "resources/portfolio_data"

conn = duckdb.connect(export_from)
conn.execute(f"EXPORT DATABASE '{export_to}'")
15 changes: 15 additions & 0 deletions utils/import_duckdb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
Import the DuckDB database schema and data from a directory where it was
previously exported by a user. This is preferred over version controlling the
DB file itself due to merge conflicts and other issues that arise with binary
files.
"""
import duckdb

# The directory to import the DB file from.
import_from = "resources/portfolio_data"
# The directory to load the DB into.
import_to = "resources/portfolio.db"

conn = duckdb.connect(import_to)
conn.execute(f"IMPORT DATABASE '{import_from}'")

0 comments on commit 56cdb96

Please sign in to comment.