feat: Implement stcache list command

This commit is contained in:
Felicitas Pojtinger
2021-11-21 01:44:08 +01:00
parent 43053d83b9
commit 4ad796bb17
3 changed files with 98 additions and 8 deletions
+6 -6
View File
@@ -16,26 +16,26 @@ type SQLite struct {
db *sql.DB
}
func (d *SQLite) Open() error {
func (s *SQLite) Open() error {
// Create leading directories for database
leadingDir, _ := filepath.Split(d.DBPath)
leadingDir, _ := filepath.Split(s.DBPath)
if err := os.MkdirAll(leadingDir, os.ModePerm); err != nil {
return err
}
// Open the DB
db, err := sql.Open("sqlite3", d.DBPath)
db, err := sql.Open("sqlite3", s.DBPath)
if err != nil {
return err
}
// Configure the db
db.SetMaxOpenConns(1) // Prevent "database locked" errors
d.db = db
s.db = db
// Run migrations if set
if d.Migrations != nil {
if _, err := migrate.Exec(d.db, "sqlite3", d.Migrations, migrate.Up); err != nil {
if s.Migrations != nil {
if _, err := migrate.Exec(s.db, "sqlite3", s.Migrations, migrate.Up); err != nil {
return err
}
}