-
Notifications
You must be signed in to change notification settings - Fork 496
/
effect_batch_insert_builder.go
60 lines (52 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
package history
import (
"context"
"github.com/guregu/null"
"github.com/stellar/go/support/db"
)
// EffectBatchInsertBuilder is used to insert effects into the
// history_effects table
type EffectBatchInsertBuilder interface {
Add(
accountID FutureAccountID,
muxedAccount null.String,
operationID int64,
order uint32,
effectType EffectType,
details []byte,
) error
Exec(ctx context.Context, session db.SessionInterface) error
}
// effectBatchInsertBuilder is a simple wrapper around db.BatchInsertBuilder
type effectBatchInsertBuilder struct {
table string
builder db.FastBatchInsertBuilder
}
// NewEffectBatchInsertBuilder constructs a new EffectBatchInsertBuilder instance
func (q *Q) NewEffectBatchInsertBuilder() EffectBatchInsertBuilder {
return &effectBatchInsertBuilder{
table: "history_effects",
builder: db.FastBatchInsertBuilder{},
}
}
// Add adds a effect to the batch
func (i *effectBatchInsertBuilder) Add(
accountID FutureAccountID,
muxedAccount null.String,
operationID int64,
order uint32,
effectType EffectType,
details []byte,
) error {
return i.builder.Row(map[string]interface{}{
"history_account_id": accountID,
"address_muxed": muxedAccount,
"history_operation_id": operationID,
"order": order,
"type": effectType,
"details": string(details),
})
}
func (i *effectBatchInsertBuilder) Exec(ctx context.Context, session db.SessionInterface) error {
return i.builder.Exec(ctx, session, i.table)
}