1
0
mirror of https://github.com/phiresky/sql.js-httpvfs.git synced 2024-11-08 20:22:44 +01:00
sql.js-httpvfs/create_db.sh
2021-04-27 15:48:20 +02:00

28 lines
797 B
Bash
Executable File

set -eu
indb="$1"
outdir="$2"
# for chunked mode, we need to know the database size in bytes beforehand
bytes="$(stat --printf="%s" "$indb")"
# set chunk size to 10MiB (needs to be a multiple of the `pragma page_size`!)
serverChunkSize=$((10 * 1024 * 1024))
suffixLength=3
rm -f "$outdir/db.sqlite3"*
split "$indb" --bytes=$serverChunkSize "$outdir/db.sqlite3." --suffix-length=$suffixLength --numeric-suffixes
# set request chunk size to match page size
requestChunkSize="$(sqlite3 "$indb" 'pragma page_size')"
# write a json config
echo '
{
"serverMode": "chunked",
"requestChunkSize": '$requestChunkSize',
"databaseLengthBytes": '$bytes',
"serverChunkSize": '$serverChunkSize',
"urlPrefix": "db.sqlite3.",
"suffixLength": '$suffixLength'
}
' > "$outdir/config.json"