Rename package files for consistency

This commit is contained in:
NeilClack
2026-06-24 23:18:52 -05:00
parent 57500308b0
commit cd79a6ffa1
2 changed files with 0 additions and 49 deletions
-49
View File
@@ -1,49 +0,0 @@
// Package db provides a database connection and functions for interacting with the database.
// The DB object should be held and maintained by the application, not by this package.
// The application should be responsible for connecting to, migrating, and initial population
// of the database. This package should only provide the schema definitions and helper functions.
// Schema definitions should clone API response structures as closely as possible.
package db
import (
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
// Connect to the database and return the gorm.DB object.
func Connect(dbpath string) (*gorm.DB, error) {
db, err := gorm.Open(sqlite.Open(dbpath), &gorm.Config{})
if err != nil {
return nil, err
}
// Set pragmas
sqlDB, err := db.DB()
if err != nil {
return nil, err
}
pragmas := []string{
"PRAGMA journal_mode=WAL",
"PRAGMA synchronous=FULL",
"PRAGMA foreign_keys=ON",
"PRAGMA busy_timeout=5000",
}
for _, pragma := range pragmas {
if _, err := sqlDB.Exec(pragma); err != nil {
return nil, err
}
}
return db, nil
}
// Migrate the database schema
func Migrate(db *gorm.DB) error {
// Pass all models to be migrated to this function call.
if err := db.AutoMigrate(&AppConfig{}, &Log{}, &Proclamation{}, &ProclamationCategory{}, &SolfeggioFrequency{}, &AudioFile{}); err != nil {
return err
}
return nil
}