1
1
// Create inserts the {{ .Struct.Name }} to the database.
2
2
func (r *{{ .Struct.Name }}) Create(db Queryer) error {
3
+ return r.CreateContext(context.Background(), db)
4
+ }
5
+
6
+ // Get{{ .Struct.Name }}ByPk select the {{ .Struct.Name }} from the database.
7
+ func Get{{ .Struct.Name }}ByPk(db Queryer, {{ createSelectByPkFuncParams .Struct }}) (*{{ .Struct.Name }}, error) {
8
+ return Get{{ .Struct.Name }}ByPkContext(context.Background(), db, {{ createSelectByPkSQLParams .Struct }})
9
+ }
10
+
11
+ // CreateContext inserts the {{ .Struct.Name }} to the database.
12
+ func (r *{{ .Struct.Name }}) CreateContext(ctx context.Context, db Queryer) error {
3
13
{{- if .Struct.Table.AutoGenPk }}
4
- err := db.QueryRow(
14
+ err := db.QueryRowContext(ctx,
5
15
`{{ createInsertSQL .Struct }}`,
6
16
{{ createInsertParams .Struct }}).Scan({{ createInsertScan .Struct }})
7
17
{{- else }}
8
- _, err := db.Exec(
18
+ _, err := db.ExecContext(ctx,
9
19
`{{ createInsertSQL .Struct }}`,
10
20
{{ createInsertParams .Struct }})
11
21
{{- end }}
@@ -15,10 +25,10 @@ func (r *{{ .Struct.Name }}) Create(db Queryer) error {
15
25
return nil
16
26
}
17
27
18
- // Get{{ .Struct.Name }}ByPk select the {{ .Struct.Name }} from the database.
19
- func Get{{ .Struct.Name }}ByPk( db Queryer, {{ createSelectByPkFuncParams .Struct }}) (*{{ .Struct.Name }}, error) {
28
+ // Get{{ .Struct.Name }}ByPkContext select the {{ .Struct.Name }} from the database.
29
+ func Get{{ .Struct.Name }}ByPkContext(ctx context.Context, db Queryer, {{ createSelectByPkFuncParams .Struct }}) (*{{ .Struct.Name }}, error) {
20
30
var r {{ .Struct.Name }}
21
- err := db.QueryRow(
31
+ err := db.QueryRowContext(ctx,
22
32
`{{ createSelectByPkSQL .Struct }}`,
23
33
{{ createSelectByPkSQLParams .Struct }}).Scan({{ createSelectByPkScan .Struct }})
24
34
if err != nil {
0 commit comments