This commit is contained in:
2025-03-13 02:51:40 -04:00
parent 46d93a62a1
commit 5657d40c02
24 changed files with 1133 additions and 31 deletions

View File

@ -0,0 +1,33 @@
package database
import (
"os"
"path/filepath"
"github.com/glebarez/sqlite"
"gorm.io/gorm"
)
func NewSQLiteConnection(name string) (*gorm.DB, error) {
// Find config diretory
configDir, err := os.UserConfigDir()
if err != nil {
return nil, err
}
// Create database directory if not exists
settingsPath := filepath.Join(configDir, "trevstack")
err = os.MkdirAll(settingsPath, 0766)
if err != nil {
return nil, err
}
// Open database
dbPath := filepath.Join(settingsPath, name)
db, err := gorm.Open(sqlite.Open(dbPath), &gorm.Config{})
if err != nil {
return nil, err
}
return db, nil
}