19e86b8c04
* First pass at centralized database reference. Closes #282 * Add verbose logging option to launch.json * Clear current broadcaster on stream end. Closes #285 * Fix typo in verbose launch args * Add support for purging tailwind styles. For #224 * Don't need to pass db as param since it is stored * Commit updated Javascript packages Co-authored-by: Owncast <owncast@owncast.online>
38 lines
810 B
Go
38 lines
810 B
Go
// This is a centralized place to connect to the database, and hold a reference to it.
|
|
// Other packages can share this reference. This package would also be a place to add any kind of
|
|
// persistence-related convenience methods or migrations.
|
|
|
|
package data
|
|
|
|
import (
|
|
"database/sql"
|
|
"os"
|
|
|
|
"github.com/owncast/owncast/config"
|
|
"github.com/owncast/owncast/utils"
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
var _db *sql.DB
|
|
|
|
func GetDatabase() *sql.DB {
|
|
return _db
|
|
}
|
|
|
|
func SetupPersistence() {
|
|
file := config.Config.DatabaseFilePath
|
|
|
|
// Create empty DB file if it doesn't exist.
|
|
if !utils.DoesFileExists(file) {
|
|
log.Traceln("Creating new database at", file)
|
|
|
|
_, err := os.Create(file)
|
|
if err != nil {
|
|
log.Fatal(err.Error())
|
|
}
|
|
}
|
|
|
|
sqliteDatabase, _ := sql.Open("sqlite3", file)
|
|
_db = sqliteDatabase
|
|
}
|