diff options
| author | David Schlachter <t480-debian-git@schlachter.ca> | 2026-01-07 23:14:56 -0500 |
|---|---|---|
| committer | David Schlachter <t480-debian-git@schlachter.ca> | 2026-01-07 23:14:56 -0500 |
| commit | 729eca86cd34c1d93c220315e4736836634f84ed (patch) | |
| tree | 1ee82db4a01aa8fd5f57699ab83adf35ec151a33 /main.go | |
| parent | da81f01d67fcc0d40abd95367d9d049d79c7cd21 (diff) | |
Move all DB setup to its own file
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 28 |
1 files changed, 2 insertions, 26 deletions
@@ -3,7 +3,6 @@ package main import ( - "database/sql" "log" _ "github.com/mattn/go-sqlite3" @@ -13,32 +12,9 @@ const rawDictionary = "/home/david/work/french-wiktionary-flashcards/raw-wiktext const dictionary = "/home/david/work/french-wiktionary-flashcards/raw-wiktextract-data.sqlite3" func main() { - db, err := sql.Open("sqlite3", dictionary) + _, err := setupDatabase() if err != nil { - log.Fatalf("opening DB '%s': %s", dictionary, err) - } - defer db.Close() - - _, err = db.Exec("create table IF NOT EXISTS words (word text not null, definition text);") - if err != nil { - log.Fatalf("creating table: %s", err) - } - - _, err = db.Exec("PRAGMA synchronous = OFF;") - if err != nil { - log.Fatalf("setting risky writes: %s", err) - } - - row := db.QueryRow(`SELECT count(*) as count from words`) - var count int - err = row.Scan(&count) - if err != nil { - log.Fatalf("counting rows: %s", err) - } - if count == 0 { - if err = readDictionary(db); err != nil { - log.Fatalf("failed to prepare dictionary: %s", err) - } + log.Fatalf("setting up database: %s", err) } } |
