Skip to content

Add option for cache. #6

@aero

Description

@aero

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions