You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
1.6 KiB
72 lines
1.6 KiB
8 years ago
|
package testfixtures
|
||
|
|
||
|
import (
|
||
|
"database/sql"
|
||
|
"fmt"
|
||
|
)
|
||
|
|
||
|
const (
|
||
|
paramTypeDollar = iota + 1
|
||
|
paramTypeQuestion
|
||
4 years ago
|
paramTypeAtSign
|
||
8 years ago
|
)
|
||
|
|
||
|
type loadFunction func(tx *sql.Tx) error
|
||
|
|
||
4 years ago
|
type helper interface {
|
||
8 years ago
|
init(*sql.DB) error
|
||
|
disableReferentialIntegrity(*sql.DB, loadFunction) error
|
||
|
paramType() int
|
||
6 years ago
|
databaseName(queryable) (string, error)
|
||
|
tableNames(queryable) ([]string, error)
|
||
|
isTableModified(queryable, string) (bool, error)
|
||
|
afterLoad(queryable) error
|
||
8 years ago
|
quoteKeyword(string) string
|
||
|
whileInsertOnTable(*sql.Tx, string, func() error) error
|
||
|
}
|
||
|
|
||
6 years ago
|
type queryable interface {
|
||
|
Exec(string, ...interface{}) (sql.Result, error)
|
||
|
Query(string, ...interface{}) (*sql.Rows, error)
|
||
|
QueryRow(string, ...interface{}) *sql.Row
|
||
|
}
|
||
|
|
||
|
// batchSplitter is an interface with method which returns byte slice for
|
||
|
// splitting SQL batches. This need to split sql statements and run its
|
||
|
// separately.
|
||
|
//
|
||
|
// For Microsoft SQL Server batch splitter is "GO". For details see
|
||
|
// https://docs.microsoft.com/en-us/sql/t-sql/language-elements/sql-server-utilities-statements-go
|
||
|
type batchSplitter interface {
|
||
|
splitter() []byte
|
||
|
}
|
||
|
|
||
|
var (
|
||
4 years ago
|
_ helper = &mySQL{}
|
||
|
_ helper = &postgreSQL{}
|
||
|
_ helper = &sqlite{}
|
||
|
_ helper = &sqlserver{}
|
||
6 years ago
|
)
|
||
|
|
||
8 years ago
|
type baseHelper struct{}
|
||
|
|
||
6 years ago
|
func (baseHelper) init(_ *sql.DB) error {
|
||
8 years ago
|
return nil
|
||
|
}
|
||
|
|
||
6 years ago
|
func (baseHelper) quoteKeyword(str string) string {
|
||
8 years ago
|
return fmt.Sprintf(`"%s"`, str)
|
||
|
}
|
||
|
|
||
6 years ago
|
func (baseHelper) whileInsertOnTable(_ *sql.Tx, _ string, fn func() error) error {
|
||
8 years ago
|
return fn()
|
||
|
}
|
||
6 years ago
|
|
||
|
func (baseHelper) isTableModified(_ queryable, _ string) (bool, error) {
|
||
|
return true, nil
|
||
|
}
|
||
|
|
||
|
func (baseHelper) afterLoad(_ queryable) error {
|
||
|
return nil
|
||
|
}
|