MySQL execution and scan support.

This commit is contained in:
go-jet 2019-07-29 18:08:53 +02:00
parent 5dda5e1e11
commit bffa102849
34 changed files with 48216 additions and 337 deletions

View file

@ -2,6 +2,7 @@ package tests
import (
"github.com/go-jet/jet"
"github.com/go-jet/jet/internal/testutils"
"github.com/go-jet/jet/tests/.gentestdata/jetdb/dvds/model"
"github.com/google/uuid"
"gotest.tools/assert"
@ -10,18 +11,6 @@ import (
"time"
)
func assertStatementSql(t *testing.T, query jet.Statement, expectedQuery string, expectedArgs ...interface{}) {
_, args, err := query.Sql()
assert.NilError(t, err)
//assert.Equal(t, queryStr, expectedQuery)
assert.DeepEqual(t, args, expectedArgs)
debuqSql, err := query.DebugSql()
assert.NilError(t, err)
assert.Equal(t, debuqSql, expectedQuery)
}
func assertExec(t *testing.T, stmt jet.Statement, rowsAffected int64) {
res, err := stmt.Exec(db)
@ -36,44 +25,44 @@ func assertExecErr(t *testing.T, stmt jet.Statement, errorStr string) {
assert.Error(t, err, errorStr)
}
func boolPtr(b bool) *bool {
func BoolPtr(b bool) *bool {
return &b
}
func int16Ptr(i int16) *int16 {
func Int16Ptr(i int16) *int16 {
return &i
}
func int32Ptr(i int32) *int32 {
func Int32Ptr(i int32) *int32 {
return &i
}
func int64Ptr(i int64) *int64 {
func Int64Ptr(i int64) *int64 {
return &i
}
func stringPtr(s string) *string {
func StringPtr(s string) *string {
return &s
}
func byteArrayPtr(arr []byte) *[]byte {
func ByteArrayPtr(arr []byte) *[]byte {
return &arr
}
func float32Ptr(f float32) *float32 {
func Float32Ptr(f float32) *float32 {
return &f
}
func float64Ptr(f float64) *float64 {
func Float64Ptr(f float64) *float64 {
return &f
}
func uuidPtr(u string) *uuid.UUID {
func UUIDPtr(u string) *uuid.UUID {
newUUID := uuid.MustParse(u)
return &newUUID
}
func timeWithoutTimeZone(t string) *time.Time {
func TimeWithoutTimeZone(t string) *time.Time {
newTime, err := time.Parse("15:04:05", t)
if err != nil {
@ -83,7 +72,7 @@ func timeWithoutTimeZone(t string) *time.Time {
return &newTime
}
func timeWithTimeZone(t string) *time.Time {
func TimeWithTimeZone(t string) *time.Time {
newTimez, err := time.Parse("15:04:05 -0700", t)
if err != nil {
@ -93,24 +82,7 @@ func timeWithTimeZone(t string) *time.Time {
return &newTimez
}
func timestampWithoutTimeZone(t string, precision int) *time.Time {
precisionStr := ""
if precision > 0 {
precisionStr = "." + strings.Repeat("9", precision)
}
newTime, err := time.Parse("2006-01-02 15:04:05"+precisionStr+" +0000", t+" +0000")
if err != nil {
panic(err)
}
return &newTime
}
func timestampWithTimeZone(t string, precision int) *time.Time {
func TimestampWithTimeZone(t string, precision int) *time.Time {
precisionStr := ""
@ -132,12 +104,12 @@ var customer0 = model.Customer{
StoreID: 1,
FirstName: "Mary",
LastName: "Smith",
Email: stringPtr("mary.smith@sakilacustomer.org"),
Email: StringPtr("mary.smith@sakilacustomer.org"),
AddressID: 5,
Activebool: true,
CreateDate: *timestampWithoutTimeZone("2006-02-14 00:00:00", 0),
LastUpdate: timestampWithoutTimeZone("2013-05-26 14:49:45.738", 3),
Active: int32Ptr(1),
CreateDate: *testutils.TimestampWithoutTimeZone("2006-02-14 00:00:00", 0),
LastUpdate: testutils.TimestampWithoutTimeZone("2013-05-26 14:49:45.738", 3),
Active: Int32Ptr(1),
}
var customer1 = model.Customer{
@ -145,12 +117,12 @@ var customer1 = model.Customer{
StoreID: 1,
FirstName: "Patricia",
LastName: "Johnson",
Email: stringPtr("patricia.johnson@sakilacustomer.org"),
Email: StringPtr("patricia.johnson@sakilacustomer.org"),
AddressID: 6,
Activebool: true,
CreateDate: *timestampWithoutTimeZone("2006-02-14 00:00:00", 0),
LastUpdate: timestampWithoutTimeZone("2013-05-26 14:49:45.738", 3),
Active: int32Ptr(1),
CreateDate: *testutils.TimestampWithoutTimeZone("2006-02-14 00:00:00", 0),
LastUpdate: testutils.TimestampWithoutTimeZone("2013-05-26 14:49:45.738", 3),
Active: Int32Ptr(1),
}
var lastCustomer = model.Customer{
@ -158,10 +130,10 @@ var lastCustomer = model.Customer{
StoreID: 2,
FirstName: "Austin",
LastName: "Cintron",
Email: stringPtr("austin.cintron@sakilacustomer.org"),
Email: StringPtr("austin.cintron@sakilacustomer.org"),
AddressID: 605,
Activebool: true,
CreateDate: *timestampWithoutTimeZone("2006-02-14 00:00:00", 0),
LastUpdate: timestampWithoutTimeZone("2013-05-26 14:49:45.738", 3),
Active: int32Ptr(1),
CreateDate: *testutils.TimestampWithoutTimeZone("2006-02-14 00:00:00", 0),
LastUpdate: testutils.TimestampWithoutTimeZone("2013-05-26 14:49:45.738", 3),
Active: Int32Ptr(1),
}