From c11e7a6956482f56502e39dc38af388032ff1d2b Mon Sep 17 00:00:00 2001 From: aceberg <1502200+aceberg@users.noreply.github.com> Date: Fri, 6 Oct 2023 22:56:11 +0700 Subject: [PATCH] DB fix --- internal/db/sqlite.go | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/internal/db/sqlite.go b/internal/db/sqlite.go index bf83438..ef07bdf 100644 --- a/internal/db/sqlite.go +++ b/internal/db/sqlite.go @@ -1,7 +1,6 @@ package db import ( - "log" "sync" "github.com/jmoiron/sqlx" @@ -40,9 +39,7 @@ func Select(path string) (dbHosts []models.Host) { err := db.Select(&dbHosts, sqlStatement) mu.Unlock() - if err != nil { - log.Fatal("ERROR: db.Select: ", err) - } + check.IfError(err) return dbHosts } @@ -50,7 +47,7 @@ func Select(path string) (dbHosts []models.Host) { // SelectHist - select all history func SelectHist(path string) (hist []models.History) { - sqlStatement := `SELECT * FROM "history" ORDER BY DATE DESC` + sqlStatement := `SELECT * FROM "history" ORDER BY ID DESC` mu.Lock() db, _ := sqlx.Connect("sqlite", path) @@ -59,9 +56,7 @@ func SelectHist(path string) (hist []models.History) { err := db.Select(&hist, sqlStatement) mu.Unlock() - if err != nil { - log.Fatal("ERROR: db.SelectHist: ", err) - } + check.IfError(err) return hist }