summaryrefslogtreecommitdiff
path: root/setup.go
diff options
context:
space:
mode:
Diffstat (limited to 'setup.go')
-rw-r--r--setup.go16
1 files changed, 13 insertions, 3 deletions
diff --git a/setup.go b/setup.go
index 47005e1..49aedd4 100644
--- a/setup.go
+++ b/setup.go
@@ -3,12 +3,13 @@ package main
import (
"bufio"
"database/sql"
- "encoding/json"
"fmt"
"html/template"
"log"
"os"
"strings"
+
+ "github.com/goccy/go-json"
)
type rawDictionaryEntry struct {
@@ -65,10 +66,15 @@ func readDictionary(db *sql.DB) error {
panic(err)
}
+ tx, err := db.Begin()
+ if err != nil {
+ return fmt.Errorf("starting transaction: %w", err)
+ }
+
// Set up a prepared statement
- stmt, err := db.Prepare("insert into words(word, definition) values(?, ?)")
+ stmt, err := tx.Prepare("insert into words(word, definition) values(?, ?)")
if err != nil {
- log.Fatal(err)
+ return fmt.Errorf("preparing statement: %w", err)
}
defer stmt.Close()
@@ -141,6 +147,10 @@ func readDictionary(db *sql.DB) error {
return fmt.Errorf("scanning: %w", err)
}
+ if err := tx.Commit(); err != nil {
+ return fmt.Errorf("committing: %w", err)
+ }
+
log.Printf("prepared %d dictionary entries", wordsAdded)
return nil