forked from stellar/go
/
participants.go
48 lines (40 loc) · 1.67 KB
/
participants.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
package history
import (
"context"
"github.com/stellar/go/support/db"
)
// QParticipants defines ingestion participant related queries.
type QParticipants interface {
QCreateAccountsHistory
NewTransactionParticipantsBatchInsertBuilder(maxBatchSize int) TransactionParticipantsBatchInsertBuilder
NewOperationParticipantBatchInsertBuilder(maxBatchSize int) OperationParticipantBatchInsertBuilder
}
// TransactionParticipantsBatchInsertBuilder is used to insert transaction participants into the
// history_transaction_participants table
type TransactionParticipantsBatchInsertBuilder interface {
Add(ctx context.Context, transactionID, accountID int64) error
Exec(ctx context.Context) error
}
type transactionParticipantsBatchInsertBuilder struct {
builder db.BatchInsertBuilder
}
// NewTransactionParticipantsBatchInsertBuilder constructs a new TransactionParticipantsBatchInsertBuilder instance
func (q *Q) NewTransactionParticipantsBatchInsertBuilder(maxBatchSize int) TransactionParticipantsBatchInsertBuilder {
return &transactionParticipantsBatchInsertBuilder{
builder: db.BatchInsertBuilder{
Table: q.GetTable("history_transaction_participants"),
MaxBatchSize: maxBatchSize,
},
}
}
// Add adds a new transaction participant to the batch
func (i *transactionParticipantsBatchInsertBuilder) Add(ctx context.Context, transactionID, accountID int64) error {
return i.builder.Row(ctx, map[string]interface{}{
"history_transaction_id": transactionID,
"history_account_id": accountID,
})
}
// Exec flushes all pending transaction participants to the db
func (i *transactionParticipantsBatchInsertBuilder) Exec(ctx context.Context) error {
return i.builder.Exec(ctx)
}