Last active
November 23, 2024 09:00
-
-
Save masamerc/d503a8b6ea9e2e220da70cf6cd609734 to your computer and use it in GitHub Desktop.
duck-preview.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# exit immediately | |
set -e | |
# check if filename is provided | |
if [ $# -ne 1 ]; then | |
echo "Usage: $0 <filename>" | |
exit 1 | |
fi | |
# check if file exists | |
if [ ! -f "$1" ]; then | |
echo "File not found: $1" | |
exit 1 | |
fi | |
# setup | |
filename=$1 | |
tmpdir=$(mktemp -d) | |
tmpdb=$tmpdir/duckdb.db | |
# cleanup for when script exits | |
function cleanup() { | |
if [ -d "$tmpdir" ]; then | |
rm -rf "$tmpdir" | |
fi | |
} | |
trap cleanup EXIT | |
# create a temporary duckdb database and start session | |
echo "creating database: $tmpdb" | |
echo "created table: preview from $1" | |
duckdb $tmpdb -c "CREATE TABLE preview AS SELECT * FROM '$filename';" | |
duckdb $tmpdb |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment