aboutsummaryrefslogtreecommitdiff
path: root/db/db.go
diff options
context:
space:
mode:
Diffstat (limited to 'db/db.go')
-rw-r--r--db/db.go15
1 files changed, 9 insertions, 6 deletions
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