Skip to content

Commit

Permalink
feat: justfile command to load all csv files in local database (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
dinhani-cw authored Mar 18, 2024
1 parent 6649672 commit 0b79850
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ lint:
lint-check nightly-version="":
@just _lint "{{nightly-version}}" --check "-D warnings"

# Stratus: Compile SQLx queries
sqlx:
SQLX_OFFLINE=true cargo sqlx prepare --database-url postgres://postgres:123@localhost/stratus -- --all-targets

# Stratus: Check for outdated crates
outdated:
@just _outdated
Expand All @@ -82,6 +78,24 @@ outdated:
update:
cargo update stratus

# ------------------------------------------------------------------------------
# Database tasks
# ------------------------------------------------------------------------------

# Database: Compile SQLx queries
db-compile:
SQLX_OFFLINE=true cargo sqlx prepare --database-url postgres://postgres:123@localhost/stratus -- --all-targets
alias sqlx := db-compile

# Database: Load CSV data produced by importer-offline
db-load-csv:
echo "" > data/psql.txt
echo "truncate transactions;" >> data/psql.txt
echo "truncate logs;" >> data/psql.txt
ls -tr1 data/transactions-*.csv | xargs -I{} printf "\\\\copy transactions from '$(pwd)/%s' delimiter E'\\\\t' csv header;\n" "{}" >> data/psql.txt
ls -tr1 data/logs-*.csv | xargs -I{} printf "\\\\copy logs from '$(pwd)/%s' delimiter E'\\\\t' csv header;\n" "{}" >> data/psql.txt
cat data/psql.txt | pgcli -h localhost -u postgres -d stratus --less-chatty

# ------------------------------------------------------------------------------
# Additional binaries
# ------------------------------------------------------------------------------
Expand Down

0 comments on commit 0b79850

Please sign in to comment.