forked from luno/shift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen_string_test.go
108 lines (87 loc) · 2.79 KB
/
gen_string_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
98
99
100
101
102
103
104
105
106
107
108
package shift_test
// Code generated by shiftgen at shift_test.go:116. 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 usersStr table entity. All the fields of the
// insertStr 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 (一 insertStr) Insert(ctx context.Context, tx *sql.Tx, st shift.Status) (string, error) {
var (
q strings.Builder
args []interface{}
)
q.WriteString("insert into usersStr set `id`=?, `status`=?, `created_at`=?, `updated_at`=? ")
args = append(args, 一.ID, st.ShiftStatus(), time.Now(), time.Now())
q.WriteString(", `name`=?")
args = append(args, 一.Name)
q.WriteString(", `dob`=?")
args = append(args, 一.DateOfBirth)
_, err := tx.ExecContext(ctx, q.String(), args...)
if err != nil {
return "", err
}
return 一.ID, nil
}
// Update updates the status of a usersStr table entity. All the fields of the
// updateStr receiver are updated, as well as status and updated_at.
// The entity id is returned on success or an error.
func (一 updateStr) Update(ctx context.Context, tx *sql.Tx, from shift.Status,
to shift.Status) (string, error) {
var (
q strings.Builder
args []interface{}
)
q.WriteString("update usersStr set `status`=?, `updated_at`=? ")
args = append(args, to.ShiftStatus(), time.Now())
q.WriteString(", `name`=?")
args = append(args, 一.Name)
q.WriteString(", `amount`=?")
args = append(args, 一.Amount)
q.WriteString(" where `id`=? and `status`=?")
args = append(args, 一.ID, from.ShiftStatus())
res, err := tx.ExecContext(ctx, q.String(), args...)
if err != nil {
return "", err
}
n, err := res.RowsAffected()
if err != nil {
return "", err
}
if n != 1 {
return "", errors.Wrap(shift.ErrRowCount, "updateStr", j.KV("count", n))
}
return 一.ID, nil
}
// Update updates the status of a usersStr table entity. All the fields of the
// completeStr receiver are updated, as well as status and updated_at.
// The entity id is returned on success or an error.
func (一 completeStr) Update(ctx context.Context, tx *sql.Tx, from shift.Status,
to shift.Status) (string, error) {
var (
q strings.Builder
args []interface{}
)
q.WriteString("update usersStr set `status`=?, `updated_at`=? ")
args = append(args, to.ShiftStatus(), time.Now())
q.WriteString(" where `id`=? and `status`=?")
args = append(args, 一.ID, from.ShiftStatus())
res, err := tx.ExecContext(ctx, q.String(), args...)
if err != nil {
return "", err
}
n, err := res.RowsAffected()
if err != nil {
return "", err
}
if n != 1 {
return "", errors.Wrap(shift.ErrRowCount, "completeStr", j.KV("count", n))
}
return 一.ID, nil
}