Noah Petherbridge
f0dd1d952c
* Add support for storing DM history between users in a SQLite3 database. * Opt-in by editing your settings.toml to set DirectMessageHistory/Enabled=true * Retention days (default 90) will flush old DMs on app startup. * On the front-end, DM history is checked when a DM thread is opened.
30 lines
432 B
Go
30 lines
432 B
Go
package models
|
|
|
|
import (
|
|
"database/sql"
|
|
"errors"
|
|
|
|
_ "github.com/glebarez/go-sqlite"
|
|
)
|
|
|
|
var (
|
|
DB *sql.DB
|
|
ErrNotInitialized = errors.New("database is not initialized")
|
|
)
|
|
|
|
func Initialize(connString string) error {
|
|
db, err := sql.Open("sqlite", connString)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
DB = db
|
|
|
|
// Run table migrations
|
|
if err := (DirectMessage{}).CreateTable(); err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|