-
Notifications
You must be signed in to change notification settings - Fork 0
/
trust_lines_batch_insert_builder.go
39 lines (32 loc) · 1.08 KB
/
trust_lines_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
package history
import (
"context"
"github.com/sanjayhashcash/go/support/db"
)
// TrustLinesBatchInsertBuilder is used to insert trustlines into the trust_lines table
type TrustLinesBatchInsertBuilder interface {
Add(line TrustLine) error
Exec(ctx context.Context) error
}
// trustLinesBatchInsertBuilder is a simple wrapper around db.FastBatchInsertBuilder
type trustLinesBatchInsertBuilder struct {
session db.SessionInterface
builder db.FastBatchInsertBuilder
table string
}
// NewTrustLinesBatchInsertBuilder constructs a new TrustLinesBatchInsertBuilder instance
func (q *Q) NewTrustLinesBatchInsertBuilder() TrustLinesBatchInsertBuilder {
return &trustLinesBatchInsertBuilder{
session: q,
builder: db.FastBatchInsertBuilder{},
table: "trust_lines",
}
}
// Add adds a new trustline to the batch
func (i *trustLinesBatchInsertBuilder) Add(line TrustLine) error {
return i.builder.RowStruct(line)
}
// Exec writes the batch of trust lines to the database.
func (i *trustLinesBatchInsertBuilder) Exec(ctx context.Context) error {
return i.builder.Exec(ctx, i.session, i.table)
}