-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgen_2_test.go
97 lines (76 loc) · 2.15 KB
/
gen_2_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
96
97
package shift_test
// Code generated by shiftgen at test_shift_test.go:16. DO NOT EDIT.
import (
"context"
"database/sql"
"strings"
"time"
"github.com/luno/jettison/errors"
"github.com/luno/jettison/j"
"github.com/luno/shift"
)
// Insert inserts a new tests table entity. All the fields of the
// i receiver are set, as well as status, created_at and updated_at.
// The newly created entity id is returned on success or an error.
func (一 i) Insert(
ctx context.Context, tx *sql.Tx, st shift.Status,
) (int64, error) {
var (
q strings.Builder
args []interface{}
)
q.WriteString("insert into tests set `status`=?, `created_at`=?, `updated_at`=? ")
args = append(args, st.ShiftStatus(), time.Now(), time.Now())
q.WriteString(", `i1`=?")
args = append(args, 一.I1)
q.WriteString(", `i2`=?")
args = append(args, 一.I2)
q.WriteString(", `i3`=?")
args = append(args, 一.I3)
res, err := tx.ExecContext(ctx, q.String(), args...)
if err != nil {
return 0, err
}
id, err := res.LastInsertId()
if err != nil {
return 0, err
}
return id, nil
}
// Update updates the status of a tests table entity. All the fields of the
// u receiver are updated, as well as status and updated_at.
// The entity id is returned on success or an error.
func (一 u) Update(
ctx context.Context, tx *sql.Tx, from shift.Status, to shift.Status,
) (int64, error) {
var (
q strings.Builder
args []interface{}
)
q.WriteString("update tests set `status`=?, `updated_at`=? ")
args = append(args, to.ShiftStatus(), time.Now())
q.WriteString(", `u1`=?")
args = append(args, 一.U1)
q.WriteString(", `u2`=?")
args = append(args, 一.U2)
q.WriteString(", `u3`=?")
args = append(args, 一.U3)
q.WriteString(", `u4`=?")
args = append(args, 一.U4)
q.WriteString(", `u5`=?")
args = append(args, 一.U5)
q.WriteString(" where `id`=? and `status`=?")
args = append(args, 一.ID, from.ShiftStatus())
res, err := tx.ExecContext(ctx, q.String(), args...)
if err != nil {
return 0, err
}
n, err := res.RowsAffected()
if err != nil {
return 0, err
}
if n != 1 {
return 0, errors.Wrap(shift.ErrRowCount, "u", j.KV("count", n))
}
return 一.ID, nil
}