From 8ae4d075c4d043eae604af9cad0cf5e571420a61 Mon Sep 17 00:00:00 2001 From: Grail Finder Date: Wed, 20 Nov 2024 13:21:51 +0300 Subject: Feat: migration on startup --- storage/storage.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'storage/storage.go') diff --git a/storage/storage.go b/storage/storage.go index 43162c8..edbd393 100644 --- a/storage/storage.go +++ b/storage/storage.go @@ -2,7 +2,7 @@ package storage import ( "elefant/models" - "fmt" + "log/slog" _ "github.com/glebarez/go-sqlite" "github.com/jmoiron/sqlx" @@ -17,7 +17,8 @@ type ChatHistory interface { } type ProviderSQL struct { - db *sqlx.DB + db *sqlx.DB + logger *slog.Logger } func (p ProviderSQL) ListChats() ([]models.Chat, error) { @@ -60,13 +61,13 @@ func (p ProviderSQL) RemoveChat(id uint32) error { return err } -func NewProviderSQL(dbPath string) ChatHistory { +func NewProviderSQL(dbPath string, logger *slog.Logger) ChatHistory { db, err := sqlx.Open("sqlite", dbPath) if err != nil { panic(err) } // get SQLite version - res := db.QueryRow("select sqlite_version()") - fmt.Println(res) - return ProviderSQL{db: db} + p := ProviderSQL{db: db, logger: logger} + p.Migrate() + return p } -- cgit v1.2.3