/
operation_batch_insert_builder.go
59 lines (52 loc) · 1.5 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
package history
import (
"github.com/AnneNamuli/go-stellar/support/db"
"github.com/AnneNamuli/go-stellar/xdr"
)
// OperationBatchInsertBuilder is used to insert a transaction's operations into the
// history_operations table
type OperationBatchInsertBuilder interface {
Add(
id int64,
transactionID int64,
applicationOrder uint32,
operationType xdr.OperationType,
details []byte,
sourceAccount string,
) error
Exec() 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(
id int64,
transactionID int64,
applicationOrder uint32,
operationType xdr.OperationType,
details []byte,
sourceAccount string,
) error {
return i.builder.Row(map[string]interface{}{
"id": id,
"transaction_id": transactionID,
"application_order": applicationOrder,
"type": operationType,
"details": details,
"source_account": sourceAccount,
})
}
func (i *operationBatchInsertBuilder) Exec() error {
return i.builder.Exec()
}