forked from gobuffalo/pop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pop_test.go
95 lines (77 loc) · 1.77 KB
/
pop_test.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package pop_test
import (
"log"
"os"
"testing"
"time"
_ "github.com/go-sql-driver/mysql"
_ "github.com/lib/pq"
"github.com/markbates/going/nulls"
"github.com/markbates/pop"
_ "github.com/mattn/go-sqlite3"
"github.com/stretchr/testify/suite"
)
var PDB *pop.Connection
type PostgreSQLSuite struct {
suite.Suite
}
type MySQLSuite struct {
suite.Suite
}
type SQLiteSuite struct {
suite.Suite
}
func TestSpecificSuites(t *testing.T) {
switch os.Getenv("SODA_DIALECT") {
case "postgres":
suite.Run(t, &PostgreSQLSuite{})
case "mysql":
suite.Run(t, &MySQLSuite{})
case "sqlite":
suite.Run(t, &SQLiteSuite{})
}
}
func init() {
pop.Debug = false
pop.AddLookupPaths("./")
dialect := os.Getenv("SODA_DIALECT")
var err error
PDB, err = pop.Connect(dialect)
if err != nil {
log.Panic(err)
}
pop.MapTableName("Friend", "good_friends")
pop.MapTableName("Friends", "good_friends")
}
func transaction(fn func(tx *pop.Connection)) {
PDB.Rollback(func(tx *pop.Connection) {
fn(tx)
})
}
func ts(s string) string {
return PDB.Dialect.TranslateSQL(s)
}
type User struct {
ID int `db:"id"`
Email string `db:"email"`
Name nulls.String `db:"name"`
Alive nulls.Bool `db:"alive"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
BirthDate nulls.Time `db:"birth_date"`
Bio nulls.String `db:"bio"`
Price nulls.Float64 `db:"price"`
FullName nulls.String `db:"full_name" select:"name as full_name"`
}
type Users []User
type Friend struct {
ID int `db:"id"`
FirstName string `db:"first_name"`
LastName string `db:"last_name"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
}
type Friends []Friend
type Enemy struct {
A string
}