Move store to $XDG_DATA_HOME/lmcli
Default to ~/.local/share/lmcli
This commit is contained in:
parent
8fe2a2cf53
commit
40a692f674
23
store.go
23
store.go
@ -2,6 +2,8 @@ package main
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/driver/sqlite"
|
||||
sqids "github.com/sqids/sqids-go"
|
||||
@ -26,12 +28,25 @@ type Conversation struct {
|
||||
Title string
|
||||
}
|
||||
|
||||
const (
|
||||
DATABASE_FILE string = "./data.db"
|
||||
)
|
||||
|
||||
func getDataDir() string {
|
||||
var dataDir string;
|
||||
|
||||
xdgDataHome := os.Getenv("XDG_DATA_HOME")
|
||||
if xdgDataHome != "" {
|
||||
dataDir = filepath.Join(xdgDataHome, "lmcli")
|
||||
} else {
|
||||
userHomeDir, _ := os.UserHomeDir()
|
||||
dataDir = filepath.Join(userHomeDir, ".local/share/lmcli")
|
||||
}
|
||||
|
||||
os.MkdirAll(dataDir, 0755)
|
||||
return dataDir
|
||||
}
|
||||
|
||||
func InitializeStore() (*Store, error) {
|
||||
db, err := gorm.Open(sqlite.Open(DATABASE_FILE), &gorm.Config{})
|
||||
databaseFile := filepath.Join(getDataDir(), "conversations.db")
|
||||
db, err := gorm.Open(sqlite.Open(databaseFile), &gorm.Config{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user