Skip to content

Commit 50ae839

Browse files
Add support for exclusive field for transaction options (#384)
1 parent c265024 commit 50ae839

File tree

5 files changed

+22
-8
lines changed

5 files changed

+22
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Change Log
22

33
## [master](https://github.com/arangodb/go-driver/tree/master) (N/A)
4+
- Add support for `exclusive` field for transaction options
45

56
## [1.3.0](https://github.com/arangodb/go-driver/tree/v1.3.0) (2022-03-17)
67
- Disallow unknown fields feature

database_impl.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ func (d *database) Transaction(ctx context.Context, action string, options *Tran
197197
input.IntermediateCommitSize = options.IntermediateCommitSize
198198
input.Collections.Read = options.ReadCollections
199199
input.Collections.Write = options.WriteCollections
200+
input.Collections.Exclusive = options.ExclusiveCollections
200201
}
201202
if _, err = req.SetBody(input); err != nil {
202203
return nil, WithStack(err)

database_transactions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type BeginTransactionOptions struct {
3535
MaxTransactionSize uint64
3636
}
3737

38-
// TransactionCollections is used to specify which collecitions are accessed by
38+
// TransactionCollections is used to specify which collections are accessed by
3939
// a transaction and how
4040
type TransactionCollections struct {
4141
Read []string `json:"read,omitempty"`

test/database_transaction_test.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,23 @@ func TestDatabaseTransaction(t *testing.T) {
3636
skipBelowVersion(c, "3.2", t)
3737
db := ensureDatabase(nil, c, "transaction_test", nil, t)
3838

39+
const colName = "books"
40+
ensureCollection(context.Background(), db, colName, nil, t)
41+
42+
txOptions := &driver.TransactionOptions{
43+
ReadCollections: []string{colName},
44+
WriteCollections: []string{colName},
45+
ExclusiveCollections: []string{colName},
46+
}
3947
testCases := []struct {
4048
name string
4149
action string
4250
options *driver.TransactionOptions
4351
expectResult interface{}
4452
expectError error
4553
}{
46-
{"ReturnValue", "function () { return 'worked!'; }", nil, "worked!", nil},
47-
{"ReturnError", "function () { error error; }", nil, nil, fmt.Errorf("missing/invalid action definition for transaction - Uncaught SyntaxError: Unexpected identifier - SyntaxError: Unexpected identifier\n at new Function (<anonymous>)")},
54+
{"ReturnValue", "function () { return 'worked!'; }", txOptions, "worked!", nil},
55+
{"ReturnError", "function () { error error; }", txOptions, nil, fmt.Errorf("missing/invalid action definition for transaction - Uncaught SyntaxError: Unexpected identifier - SyntaxError: Unexpected identifier\n at new Function (<anonymous>)")},
4856
}
4957

5058
for _, testCase := range testCases {
@@ -139,7 +147,7 @@ func TestTransactionAbort(t *testing.T) {
139147
// document should exist with transaction
140148
documentExists(tctx, col, meta1.Key, true, t)
141149

142-
// Now commit the transaction
150+
// Now abort the transaction
143151
if err := db.AbortTransaction(ctx, trxid, nil); err != nil {
144152
t.Fatalf("Failed to abort transaction: %s", describe(err))
145153
}

transaction.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,14 @@ type TransactionOptions struct {
4747
// performed automatically. Honored by the RocksDB storage engine only.
4848
IntermediateCommitSize *int
4949

50-
// Collections that the transaction reads from.
50+
// ReadCollections Collections that the transaction reads from.
5151
ReadCollections []string
5252

53-
// Collections that the transaction writes to.
53+
// WriteCollections Collections that the transaction writes to.
5454
WriteCollections []string
55+
56+
// ExclusiveCollections Collections that the transaction write exclusively to.
57+
ExclusiveCollections []string
5558
}
5659

5760
type transactionRequest struct {
@@ -66,8 +69,9 @@ type transactionRequest struct {
6669
}
6770

6871
type transactionCollectionsRequest struct {
69-
Read []string `json:"read,omitempty"`
70-
Write []string `json:"write,omitempty"`
72+
Read []string `json:"read,omitempty"`
73+
Write []string `json:"write,omitempty"`
74+
Exclusive []string `json:"exclusive,omitempty"`
7175
}
7276

7377
type transactionResponse struct {

0 commit comments

Comments
 (0)