removed the default cgo driver registration

This commit is contained in:
Gani Georgiev
2024-10-29 22:46:56 +02:00
parent 5a94ec9918
commit 8b42941bd3
10 changed files with 4650 additions and 4680 deletions
+1 -1
View File
@@ -202,7 +202,7 @@ func NewBaseApp(config BaseAppConfig) *BaseApp {
// apply config defaults
if app.config.DBConnect == nil {
app.config.DBConnect = dbConnect
app.config.DBConnect = DefaultDBConnect
}
if app.config.DataMaxOpenConns <= 0 {
app.config.DataMaxOpenConns = DefaultDataMaxOpenConns
@@ -1,4 +1,4 @@
//go:build !cgo
//go:build !nodefaultdriver
package core
@@ -7,7 +7,7 @@ import (
_ "modernc.org/sqlite"
)
func dbConnect(dbPath string) (*dbx.DB, error) {
func DefaultDBConnect(dbPath string) (*dbx.DB, error) {
// Note: the busy_timeout pragma must be first because
// the connection needs to be set to block on busy before WAL mode
// is set in case it hasn't been already set by another connection.
-50
View File
@@ -1,50 +0,0 @@
//go:build cgo
package core
import (
"database/sql"
"github.com/mattn/go-sqlite3"
"github.com/pocketbase/dbx"
)
func init() {
// Registers the sqlite3 driver with a ConnectHook so that we can
// initialize the default PRAGMAs.
//
// Note 1: we don't define the PRAGMA as part of the dsn string
// because not all pragmas are available.
//
// Note 2: the busy_timeout pragma must be first because
// the connection needs to be set to block on busy before WAL mode
// is set in case it hasn't been already set by another connection.
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 = -16000;
`, nil)
return err
},
},
)
dbx.BuilderFuncMap["pb_sqlite3"] = dbx.BuilderFuncMap["sqlite3"]
}
func dbConnect(dbPath string) (*dbx.DB, error) {
db, err := dbx.Open("pb_sqlite3", dbPath)
if err != nil {
return nil, err
}
return db, nil
}
+9
View File
@@ -0,0 +1,9 @@
//go:build nodefaultdriver
package core
import "github.com/pocketbase/dbx"
func DefaultDBConnect(dbPath string) (*dbx.DB, error) {
panic("DBConnect config option must be set when the nodefaultdriver tag is used!")
}