First pass at centralized database reference. Closes #282 (#289)

* 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>
This commit is contained in:
Gabe Kangas
2020-10-26 08:55:31 -07:00
committed by GitHub
parent 6d0aa4bdd1
commit 19e86b8c04
6 changed files with 69 additions and 33 deletions

View File

@@ -2,36 +2,22 @@ package chat
import (
"database/sql"
"os"
"time"
_ "github.com/mattn/go-sqlite3"
"github.com/owncast/owncast/config"
"github.com/owncast/owncast/core/data"
"github.com/owncast/owncast/models"
"github.com/owncast/owncast/utils"
log "github.com/sirupsen/logrus"
)
var _db *sql.DB
func setupPersistence() {
file := config.Config.ChatDatabaseFilePath
// Create empty DB file if it doesn't exist.
if !utils.DoesFileExists(file) {
log.Traceln("Creating new chat history database at", file)
_, err := os.Create(file)
if err != nil {
log.Fatal(err.Error())
}
}
sqliteDatabase, _ := sql.Open("sqlite3", file)
_db = sqliteDatabase
createTable(sqliteDatabase)
_db = data.GetDatabase()
createTable()
}
func createTable(db *sql.DB) {
func createTable() {
createTableSQL := `CREATE TABLE IF NOT EXISTS messages (
"id" string NOT NULL PRIMARY KEY,
"author" TEXT,