/
claimable_balance_batch_insert_builder.go
46 lines (38 loc) · 1.37 KB
/
claimable_balance_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
package history
import (
"context"
"github.com/stellar/go/support/db"
)
// ClaimableBalanceBatchInsertBuilder is used to insert claimable balance into the
// claimable_balances table
type ClaimableBalanceBatchInsertBuilder interface {
Add(claimableBalance ClaimableBalance) error
Exec(ctx context.Context) error
Len() int
}
// ClaimableBalanceBatchInsertBuilder is a simple wrapper around db.FastBatchInsertBuilder
type claimableBalanceBatchInsertBuilder struct {
session db.SessionInterface
builder db.FastBatchInsertBuilder
table string
}
// NewClaimableBalanceBatchInsertBuilder constructs a new ClaimableBalanceBatchInsertBuilder instance
func (q *Q) NewClaimableBalanceBatchInsertBuilder() ClaimableBalanceBatchInsertBuilder {
return &claimableBalanceBatchInsertBuilder{
session: q,
builder: db.FastBatchInsertBuilder{},
table: "claimable_balances",
}
}
// Add adds a new claimable balance to the batch
func (i *claimableBalanceBatchInsertBuilder) Add(claimableBalance ClaimableBalance) error {
return i.builder.RowStruct(claimableBalance)
}
// Exec writes the batch of claimable balances to the database.
func (i *claimableBalanceBatchInsertBuilder) Exec(ctx context.Context) error {
return i.builder.Exec(ctx, i.session, i.table)
}
// Len returns the number of items in the batch.
func (i *claimableBalanceBatchInsertBuilder) Len() int {
return i.builder.Len()
}