mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2024-11-10 08:57:25 +01:00
Merge pull request #120 from ClusterCockpit/optimize-sqlite-db-setup
Enable SQL hooks for statement debugging
This commit is contained in:
commit
797d5da80b
@ -5,11 +5,14 @@
|
|||||||
package repository
|
package repository
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"database/sql"
|
||||||
"log"
|
"log"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
|
"github.com/mattn/go-sqlite3"
|
||||||
|
"github.com/qustavo/sqlhooks/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -45,15 +48,15 @@ func Connect(driver string, db string) {
|
|||||||
|
|
||||||
switch driver {
|
switch driver {
|
||||||
case "sqlite3":
|
case "sqlite3":
|
||||||
// sql.Register("sqlite3WithHooks", sqlhooks.Wrap(&sqlite3.SQLiteDriver{}, &Hooks{}))
|
sql.Register("sqlite3WithHooks", sqlhooks.Wrap(&sqlite3.SQLiteDriver{}, &Hooks{}))
|
||||||
|
|
||||||
// - Set WAL mode (not strictly necessary each time because it's persisted in the database, but good for first run)
|
// - Set WAL mode (not strictly necessary each time because it's persisted in the database, but good for first run)
|
||||||
// - Set busy timeout, so concurrent writers wait on each other instead of erroring immediately
|
// - Set busy timeout, so concurrent writers wait on each other instead of erroring immediately
|
||||||
// - Enable foreign key checks
|
// - Enable foreign key checks
|
||||||
opts.URL += "?_journal=WAL&_timeout=5000&_fk=true"
|
opts.URL += "?_journal=WAL&_timeout=5000&_fk=true"
|
||||||
|
|
||||||
// dbHandle, err = sqlx.Open("sqlite3WithHooks", fmt.Sprintf("%s?_foreign_keys=on", db))
|
dbHandle, err = sqlx.Open("sqlite3WithHooks", opts.URL)
|
||||||
dbHandle, err = sqlx.Open("sqlite3", opts.URL)
|
// dbHandle, err = sqlx.Open("sqlite3", opts.URL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user