/
order.sql.go
125 lines (110 loc) · 2.51 KB
/
order.sql.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Code generated by sqlc. DO NOT EDIT.
// source: order.sql
package db
import (
"context"
"github.com/jackc/pgtype"
)
const createOrders = `-- name: CreateOrders :one
INSERT INTO orders (
trx_id,
payment_trx_id,
lock_items,
status,
customer_name,
customer_address
)
VALUES (
$1,
$2,
$3,
$4,
$5,
$6
)
RETURNING id
`
type CreateOrdersParams struct {
TrxID string `json:"trx_id"`
PaymentTrxID string `json:"payment_trx_id"`
LockItems pgtype.JSON `json:"lock_items"`
Status string `json:"status"`
CustomerName string `json:"customer_name"`
CustomerAddress string `json:"customer_address"`
}
func (q *Queries) CreateOrders(ctx context.Context, arg CreateOrdersParams) (int32, error) {
row := q.db.QueryRow(ctx, createOrders,
arg.TrxID,
arg.PaymentTrxID,
arg.LockItems,
arg.Status,
arg.CustomerName,
arg.CustomerAddress,
)
var id int32
err := row.Scan(&id)
return id, err
}
const createOrdersDetail = `-- name: CreateOrdersDetail :one
INSERT INTO order_detail (
order_id,
name,
quantity,
price
)
VALUES (
$1,
$2,
$3,
$4
)
RETURNING id
`
type CreateOrdersDetailParams struct {
OrderID int32 `json:"order_id"`
Name string `json:"name"`
Quantity int32 `json:"quantity"`
Price pgtype.Numeric `json:"price"`
}
func (q *Queries) CreateOrdersDetail(ctx context.Context, arg CreateOrdersDetailParams) (int32, error) {
row := q.db.QueryRow(ctx, createOrdersDetail,
arg.OrderID,
arg.Name,
arg.Quantity,
arg.Price,
)
var id int32
err := row.Scan(&id)
return id, err
}
const orderPlaced = `-- name: OrderPlaced :one
UPDATE orders SET
status = $1
WHERE payment_trx_id = $2
RETURNING id AS res
`
type OrderPlacedParams struct {
Status string `json:"status"`
PaymentTrxID string `json:"payment_trx_id"`
}
func (q *Queries) OrderPlaced(ctx context.Context, arg OrderPlacedParams) (int32, error) {
row := q.db.QueryRow(ctx, orderPlaced, arg.Status, arg.PaymentTrxID)
var res int32
err := row.Scan(&res)
return res, err
}
const selectPayloads = `-- name: SelectPayloads :one
SELECT id, lock_items
FROM orders
WHERE payment_trx_id = $1
`
type SelectPayloadsRow struct {
ID int32 `json:"id"`
LockItems pgtype.JSON `json:"lock_items"`
}
func (q *Queries) SelectPayloads(ctx context.Context, paymentTrxID string) (SelectPayloadsRow, error) {
row := q.db.QueryRow(ctx, selectPayloads, paymentTrxID)
var i SelectPayloadsRow
err := row.Scan(&i.ID, &i.LockItems)
return i, err
}