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.
30 lines
431 B
Go
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
|
|
}
|