-
Notifications
You must be signed in to change notification settings - Fork 0
/
accounts_batch_insert_builder.go
39 lines (32 loc) · 1.06 KB
/
accounts_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"
)
// AccountsBatchInsertBuilder is used to insert accounts into the accounts table
type AccountsBatchInsertBuilder interface {
Add(account AccountEntry) error
Exec(ctx context.Context) error
}
// AccountsBatchInsertBuilder is a simple wrapper around db.FastBatchInsertBuilder
type accountsBatchInsertBuilder struct {
session db.SessionInterface
builder db.FastBatchInsertBuilder
table string
}
// NewAccountsBatchInsertBuilder constructs a new AccountsBatchInsertBuilder instance
func (q *Q) NewAccountsBatchInsertBuilder() AccountsBatchInsertBuilder {
return &accountsBatchInsertBuilder{
session: q,
builder: db.FastBatchInsertBuilder{},
table: "accounts",
}
}
// Add adds a new account to the batch
func (i *accountsBatchInsertBuilder) Add(account AccountEntry) error {
return i.builder.RowStruct(account)
}
// Exec writes the batch of accounts to the database.
func (i *accountsBatchInsertBuilder) Exec(ctx context.Context) error {
return i.builder.Exec(ctx, i.session, i.table)
}