From 786ff5cff8d6fdca6dd80bd0807619bdea5f0f51 Mon Sep 17 00:00:00 2001 From: "Gabriel A. Giovanini" Date: Fri, 19 Apr 2024 18:45:07 +0200 Subject: feat: Add spellfix check back for fts5 --- db/db.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'db/db.go') diff --git a/db/db.go b/db/db.go index 746c30d..b28dea2 100644 --- a/db/db.go +++ b/db/db.go @@ -4,6 +4,7 @@ import ( "context" "database/sql" "fmt" + "os" "github.com/mattn/go-sqlite3" ) @@ -42,9 +43,8 @@ func (d *DB) Migrate(ctx context.Context) error { _, err := d.db.ExecContext( ctx, `CREATE VIRTUAL TABLE IF NOT EXISTS words USING fts5 (word, line); - CREATE VIRTUAL TABLE IF NOT EXISTS words_terms USING fts4aux(words); - CREATE VIRTUAL TABLE IF NOT EXISTS spell USING spellfix1; - `, + CREATE VIRTUAL TABLE IF NOT EXISTS words_vocab USING fts5vocab('words', 'row'); + CREATE VIRTUAL TABLE IF NOT EXISTS spell USING spellfix1;`, ) return err } @@ -100,7 +100,7 @@ func (d *DB) SelectSpell(ctx context.Context, query string) ([]string, error) { words = append(words, w) } - return words, err + return words, nil } @@ -119,8 +119,7 @@ func (d *DB) InsertLine(ctx context.Context, word, line string) error { func (d *DB) Consolidade(ctx context.Context) error { _, err := d.db.ExecContext( ctx, - `INSERT INTO spell(word,rank) - SELECT term, documents FROM words_terms WHERE col='*'`, + `INSERT INTO spell(word) SELECT term FROM words_vocab`, ) if err != nil { return err @@ -139,6 +138,10 @@ func (d *DB) Backup(ctx context.Context, name string) error { } func (d *DB) Restore(ctx context.Context, name string) error { + if _, err := os.Stat(name); err != nil { + return err + } + srcDb, err := sql.Open("sqlite3_with_extensions", name) if err != nil { return err -- cgit v1.2.3