BareRTC/pkg/models/database.go
Noah Petherbridge 23a73620b9 Switch to mattn/go-sqlite3
Instead of the pure Go implementation of SQLite, swap in the cgo library
from mattn/go-sqlite3. On local testing this cuts the SQL query times in
half for the History modal (from 400ms per page to 150ms) and may
improve performance in production.
2025-03-17 17:58:03 -07:00

30 lines
431 B
Go

package models
import (
"database/sql"
"errors"
_ "github.com/mattn/go-sqlite3"
)
var (
DB *sql.DB
ErrNotInitialized = errors.New("database is not initialized")
)
func Initialize(connString string) error {
db, err := sql.Open("sqlite3", connString)
if err != nil {
return err
}
DB = db
// Run table migrations
if err := (DirectMessage{}).CreateTable(); err != nil {
return err
}
return nil
}