Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option for cache. #6

Open
aero opened this issue Aug 16, 2020 · 0 comments
Open

Add option for cache. #6

aero opened this issue Aug 16, 2020 · 0 comments

Comments

@aero
Copy link

aero commented Aug 16, 2020

Hi,
I made and used my own utility for similar purpose.

If csv file is very large, every .import csv procedure makes delay.
So I solved the problem with backed up dump of imported csv sqlite db.
The following is my script.

#!/bin/bash
if [[ $# -eq 0 ]]; then
    cat << HELP

Usage:

${0##*/} myfile.csv  ---> view csv fields schema and sample data.
${0##*/} myfile.csv 'select ... from myfile ... ;' ---->  query csv.

HELP
    exit 1
fi

csv_file=$1
shift

table=${csv_file%%.*}

query=".schema
select * from $table limit 1;"

if [[ "$@" ]]; then
    query="$@"
fi

if [[ -f "$table.db" ]]; then
cat << EOF | sqlite3 $table.db
.mode csv
.headers on
$query
EOF

else
cat << EOF | sqlite3
.mode csv
.import $csv_file $table
.headers on
.backup main $table.db
$query
EOF

fi

How about adding option like -c ( cache) or -d ( use database) for making dumb db at first execution and using dumped db if db file exists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant