mirror of
https://github.com/Theodor-Springmann-Stiftung/musenalm.git
synced 2025-10-30 09:45:31 +00:00
51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
package app
|
|
|
|
import (
|
|
"database/sql"
|
|
|
|
"github.com/mattn/go-sqlite3"
|
|
"github.com/pocketbase/dbx"
|
|
"github.com/pocketbase/pocketbase"
|
|
)
|
|
|
|
// INFO: this is the main application that mainly is a pocketbase wrapper
|
|
type App struct {
|
|
PB *pocketbase.PocketBase
|
|
MAConfig Config
|
|
}
|
|
|
|
func init() {
|
|
sql.Register("pb_sqlite3",
|
|
&sqlite3.SQLiteDriver{
|
|
ConnectHook: func(conn *sqlite3.SQLiteConn) error {
|
|
_, err := conn.Exec(`
|
|
PRAGMA busy_timeout = 10000;
|
|
PRAGMA journal_mode = WAL;
|
|
PRAGMA journal_size_limit = 200000000;
|
|
PRAGMA synchronous = NORMAL;
|
|
PRAGMA foreign_keys = ON;
|
|
PRAGMA temp_store = MEMORY;
|
|
PRAGMA cache_size = -32768;
|
|
`, nil)
|
|
|
|
return err
|
|
},
|
|
},
|
|
)
|
|
|
|
dbx.BuilderFuncMap["pb_sqlite3"] = dbx.BuilderFuncMap["sqlite3"]
|
|
}
|
|
|
|
func New(config Config) App {
|
|
app := pocketbase.NewWithConfig(pocketbase.Config{
|
|
DBConnect: func(dbPath string) (*dbx.DB, error) {
|
|
return dbx.Open("pb_sqlite3", dbPath)
|
|
},
|
|
})
|
|
|
|
return App{
|
|
PB: app,
|
|
MAConfig: config,
|
|
}
|
|
}
|