diff options
| author | David Schlachter <t480-debian-git@schlachter.ca> | 2026-01-07 22:53:13 -0500 |
|---|---|---|
| committer | David Schlachter <t480-debian-git@schlachter.ca> | 2026-01-07 22:53:13 -0500 |
| commit | 328f2892e01056b809851e5338ef184df5033906 (patch) | |
| tree | 011de90946d2dc6764b7e36ed9f0f25f72b44ce9 /setup.go | |
| parent | 3b4dcb36059755149457af0bd401f60f8411c649 (diff) | |
Much faster initial setup
Diffstat (limited to 'setup.go')
| -rw-r--r-- | setup.go | 16 |
1 files changed, 13 insertions, 3 deletions
@@ -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 |
