Skip to content

Commit

Permalink
seed a sqlite db ready for migration
Browse files Browse the repository at this point in the history
  • Loading branch information
Recidvst committed Jun 22, 2024
1 parent f474e92 commit fe6373b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion components/quotes/Quote.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<li class="box columns is-12 is-flex is-vcentered">
<blockquote class="column is-11 quote" :data-id="content.id" :data-type="content.type" data-booktype="bookType">
<blockquote class="column is-11 quote" :data-id="content.id" :data-type="content.type" :data-booktype="bookType">
<strong v-if="isArchive && content.identifier" @click.prevent="goToSnippet($event)">({{ content.identifier }}) </strong>{{ content.text }}
</blockquote>
<div class="icon-box" :data-clipboard="index">
Expand Down
Binary file added data/moby.db
Binary file not shown.
42 changes: 42 additions & 0 deletions data/seed.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/bash

# db name
DATABASE="moby.db"

if [ "$#" -ne 3 ]; then
echo "Usage: $0 <CONTENT_TYPE> <FILE_NAME> <BOOK_TYPE>"
exit 1
fi

# Read parameters
CONTENT_TYPE=$1
FILE_NAME=$2
BOOK_TYPE=$3

echo $CONTENT_TYPE
echo $FILE_NAME
echo $BOOK_TYPE

# Create the table if it doesn't exist
sqlite3 $DATABASE <<EOF
CREATE TABLE IF NOT EXISTS $CONTENT_TYPE (
id INTEGER PRIMARY KEY AUTOINCREMENT,
identifier INTEGER,
bookType TEXT CHECK(bookType = 'moby-dick' or bookType = 'alice') DEFAULT 'moby-dick',
content TEXT
)
EOF

# Read and parse the JSON file, then insert data into the database
jq-win64 -c '.[]' $FILE_NAME | while read -r row; do
identifier=$(echo $row | jq-win64 -r '.id')
content=$(echo $row | jq-win64 -r '.content')
bookType=$(echo $BOOK_TYPE)

sqlite3 $DATABASE <<EOF
INSERT INTO $CONTENT_TYPE (identifier, content, bookType) VALUES ('$identifier', '$(echo "$content" | sed "s/'/''/g")', '$bookType');
EOF

done

echo "Data inserted successfully for file $FILE_NAME"

0 comments on commit fe6373b

Please sign in to comment.