-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsqlassert.go
39 lines (33 loc) · 1.12 KB
/
sqlassert.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package sqlassert
import (
"database/sql"
)
const (
errTableNotExists = "table '%s' does not exist"
errTableExists = "table '%s' exists"
errColumnNotExists = "column '%s' does not exist in table '%s'"
errColumnExists = "column '%s' exists in table '%s'"
errColumnNotOfType = "column '%s' in table '%s' is not of type '%s'"
errConstraintNotExists = "constraint '%s' does not exist in table '%s'"
errConstraintExists = "constraint '%s' exists in table '%s'"
errRowNotExists = "row with criteria %v does not exist in table '%s'"
errRowExists = "row with criteria %v exists in table '%s'"
errIndexNotExists = "index '%s' does not exist in table '%s'"
errIndexExists = "index '%s' exists in table '%s'"
)
type testingT interface {
Errorf(format string, args ...interface{})
}
type rowExistsQueryBuilder func(table string, colVals map[string]interface{}) (string, []interface{})
func queryExists(
db *sql.DB,
query string,
args ...interface{},
) bool {
exists := false
err := db.QueryRow(query, args...).Scan(&exists)
if err != nil {
panic(err)
}
return exists
}