diff options
author | Grail Finder <wohilas@gmail.com> | 2024-11-20 13:21:51 +0300 |
---|---|---|
committer | Grail Finder <wohilas@gmail.com> | 2024-11-20 13:21:51 +0300 |
commit | 8ae4d075c4d043eae604af9cad0cf5e571420a61 (patch) | |
tree | 3b0eb7689a598e25dac67d889e037f3bc08c19a1 /storage/storage.go | |
parent | 74669b58fe7b58b3d2fd4ad88c03890bc53a7a1a (diff) |
Feat: migration on startup
Diffstat (limited to 'storage/storage.go')
-rw-r--r-- | storage/storage.go | 13 |
1 files changed, 7 insertions, 6 deletions
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 } |