mirror of
https://github.com/Theodor-Springmann-Stiftung/musenalm.git
synced 2025-12-16 14:15:30 +00:00
Start of creating app structure
This commit is contained in:
50
app/pb.go
Normal file
50
app/pb.go
Normal file
@@ -0,0 +1,50 @@
|
||||
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,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user