47 lines
1.2 KiB
Go
47 lines
1.2 KiB
Go
package dbx
|
|
|
|
import (
|
|
"database/sql"
|
|
"strings"
|
|
|
|
"github.com/go-jet/jet/v2/qrm"
|
|
)
|
|
|
|
// ModuleDBName is the name of the database module.
|
|
const ModuleDBName = "database"
|
|
|
|
// Queryable interface is an SQL driver object that can execute SQL statements
|
|
// for Jet.
|
|
type Queryable interface {
|
|
qrm.Queryable
|
|
Query(string, ...any) (*sql.Rows, error)
|
|
}
|
|
|
|
// Executable interface is an SQL driver object that can execute SQL statements
|
|
// for Jet.
|
|
type Executable interface {
|
|
qrm.Executable
|
|
Exec(string, ...any) (sql.Result, error)
|
|
}
|
|
|
|
// ExecutableTx interface is an SQL driver object that implements the Executable
|
|
// interface and can also begin a transaction.
|
|
type ExecutableTx interface {
|
|
Executable
|
|
Begin() (*sql.Tx, error)
|
|
}
|
|
|
|
// StringToFilter processes a string to be used as a filter in an SQL LIKE
|
|
// statement. It replaces all spaces with % and adds % to the beginning and
|
|
// end of the string.
|
|
func StringToFilter(str string) string {
|
|
// Remove any existing leading or trailing % characters
|
|
str = strings.Trim(str, "%")
|
|
|
|
// Replace all spaces with % and add % to the beginning and end of the string
|
|
str = strings.ReplaceAll(str, " ", "%")
|
|
str = "%" + str + "%"
|
|
|
|
return str
|
|
}
|