Browse Source
* 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>pull/297/head
6 changed files with 69 additions and 33 deletions
@ -0,0 +1,37 @@
@@ -0,0 +1,37 @@
|
||||
// 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 |
||||
} |
Loading…
Reference in new issue