/
effect_batch_insert_builder.go
62 lines (55 loc) · 1.49 KB
/
effect_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
package history
import (
"context"
"github.com/TosinShada/stellar-core/support/db"
"github.com/guregu/null"
)
// EffectBatchInsertBuilder is used to insert effects into the
// history_effects table
type EffectBatchInsertBuilder interface {
Add(
ctx context.Context,
accountID int64,
muxedAccount null.String,
operationID int64,
order uint32,
effectType EffectType,
details []byte,
) error
Exec(ctx context.Context) error
}
// effectBatchInsertBuilder is a simple wrapper around db.BatchInsertBuilder
type effectBatchInsertBuilder struct {
builder db.BatchInsertBuilder
}
// NewEffectBatchInsertBuilder constructs a new EffectBatchInsertBuilder instance
func (q *Q) NewEffectBatchInsertBuilder(maxBatchSize int) EffectBatchInsertBuilder {
return &effectBatchInsertBuilder{
builder: db.BatchInsertBuilder{
Table: q.GetTable("history_effects"),
MaxBatchSize: maxBatchSize,
},
}
}
// Add adds a effect to the batch
func (i *effectBatchInsertBuilder) Add(
ctx context.Context,
accountID int64,
muxedAccount null.String,
operationID int64,
order uint32,
effectType EffectType,
details []byte,
) error {
return i.builder.Row(ctx, map[string]interface{}{
"history_account_id": accountID,
"address_muxed": muxedAccount,
"history_operation_id": operationID,
"\"order\"": order,
"type": effectType,
"details": details,
})
}
func (i *effectBatchInsertBuilder) Exec(ctx context.Context) error {
return i.builder.Exec(ctx)
}