Register regexp func in init (#202)

This commit is contained in:
WithoutPants
2019-11-15 05:28:17 +11:00
committed by StashAppDev
parent 49c9b1aa9a
commit 4a5d2bd6e5

View File

@@ -3,7 +3,9 @@ package database
import ( import (
"database/sql" "database/sql"
"fmt" "fmt"
"os"
"regexp" "regexp"
"github.com/gobuffalo/packr/v2" "github.com/gobuffalo/packr/v2"
"github.com/golang-migrate/migrate/v4" "github.com/golang-migrate/migrate/v4"
"github.com/golang-migrate/migrate/v4/source" "github.com/golang-migrate/migrate/v4/source"
@@ -11,7 +13,6 @@ import (
sqlite3 "github.com/mattn/go-sqlite3" sqlite3 "github.com/mattn/go-sqlite3"
"github.com/stashapp/stash/pkg/logger" "github.com/stashapp/stash/pkg/logger"
"github.com/stashapp/stash/pkg/utils" "github.com/stashapp/stash/pkg/utils"
"os"
) )
var DB *sqlx.DB var DB *sqlx.DB
@@ -19,11 +20,13 @@ var appSchemaVersion uint = 1
const sqlite3Driver = "sqlite3_regexp" const sqlite3Driver = "sqlite3_regexp"
func Initialize(databasePath string) { func init() {
runMigrations(databasePath)
// register custom driver with regexp function // register custom driver with regexp function
registerRegexpFunc() registerRegexpFunc()
}
func Initialize(databasePath string) {
runMigrations(databasePath)
// https://github.com/mattn/go-sqlite3 // https://github.com/mattn/go-sqlite3
conn, err := sqlx.Open(sqlite3Driver, "file:"+databasePath+"?_fk=true") conn, err := sqlx.Open(sqlite3Driver, "file:"+databasePath+"?_fk=true")