/
operation_batch_insert_builder.go
67 lines (59 loc) · 1.75 KB
/
operation_batch_insert_builder.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
package history
import (
"context"
"github.com/TosinShada/monorepo/support/db"
"github.com/TosinShada/monorepo/xdr"
"github.com/guregu/null"
)
// OperationBatchInsertBuilder is used to insert a transaction's operations into the
// history_operations table
type OperationBatchInsertBuilder interface {
Add(
ctx context.Context,
id int64,
transactionID int64,
applicationOrder uint32,
operationType xdr.OperationType,
details []byte,
sourceAccount string,
sourceAcccountMuxed null.String,
) error
Exec(ctx context.Context) error
}
// operationBatchInsertBuilder is a simple wrapper around db.BatchInsertBuilder
type operationBatchInsertBuilder struct {
builder db.BatchInsertBuilder
}
// NewOperationBatchInsertBuilder constructs a new TransactionBatchInsertBuilder instance
func (q *Q) NewOperationBatchInsertBuilder(maxBatchSize int) OperationBatchInsertBuilder {
return &operationBatchInsertBuilder{
builder: db.BatchInsertBuilder{
Table: q.GetTable("history_operations"),
MaxBatchSize: maxBatchSize,
},
}
}
// Add adds a transaction's operations to the batch
func (i *operationBatchInsertBuilder) Add(
ctx context.Context,
id int64,
transactionID int64,
applicationOrder uint32,
operationType xdr.OperationType,
details []byte,
sourceAccount string,
sourceAccountMuxed null.String,
) error {
return i.builder.Row(ctx, map[string]interface{}{
"id": id,
"transaction_id": transactionID,
"application_order": applicationOrder,
"type": operationType,
"details": details,
"source_account": sourceAccount,
"source_account_muxed": sourceAccountMuxed,
})
}
func (i *operationBatchInsertBuilder) Exec(ctx context.Context) error {
return i.builder.Exec(ctx)
}