Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Change Log

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

## [1.3.0](https://github.com/arangodb/go-driver/tree/v1.3.0) (2022-03-17)
- Disallow unknown fields feature
Expand Down
1 change: 1 addition & 0 deletions database_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ func (d *database) Transaction(ctx context.Context, action string, options *Tran
input.IntermediateCommitSize = options.IntermediateCommitSize
input.Collections.Read = options.ReadCollections
input.Collections.Write = options.WriteCollections
input.Collections.Exclusive = options.ExclusiveCollections
}
if _, err = req.SetBody(input); err != nil {
return nil, WithStack(err)
Expand Down
2 changes: 1 addition & 1 deletion database_transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type BeginTransactionOptions struct {
MaxTransactionSize uint64
}

// TransactionCollections is used to specify which collecitions are accessed by
// TransactionCollections is used to specify which collections are accessed by
// a transaction and how
type TransactionCollections struct {
Read []string `json:"read,omitempty"`
Expand Down
14 changes: 11 additions & 3 deletions test/database_transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,23 @@ func TestDatabaseTransaction(t *testing.T) {
skipBelowVersion(c, "3.2", t)
db := ensureDatabase(nil, c, "transaction_test", nil, t)

const colName = "books"
ensureCollection(context.Background(), db, colName, nil, t)

txOptions := &driver.TransactionOptions{
ReadCollections: []string{colName},
WriteCollections: []string{colName},
ExclusiveCollections: []string{colName},
}
testCases := []struct {
name string
action string
options *driver.TransactionOptions
expectResult interface{}
expectError error
}{
{"ReturnValue", "function () { return 'worked!'; }", nil, "worked!", nil},
{"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>)")},
{"ReturnValue", "function () { return 'worked!'; }", txOptions, "worked!", nil},
{"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>)")},
}

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

// Now commit the transaction
// Now abort the transaction
if err := db.AbortTransaction(ctx, trxid, nil); err != nil {
t.Fatalf("Failed to abort transaction: %s", describe(err))
}
Expand Down
12 changes: 8 additions & 4 deletions transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,14 @@ type TransactionOptions struct {
// performed automatically. Honored by the RocksDB storage engine only.
IntermediateCommitSize *int

// Collections that the transaction reads from.
// ReadCollections Collections that the transaction reads from.
ReadCollections []string

// Collections that the transaction writes to.
// WriteCollections Collections that the transaction writes to.
WriteCollections []string

// ExclusiveCollections Collections that the transaction write exclusively to.
ExclusiveCollections []string
}

type transactionRequest struct {
Expand All @@ -66,8 +69,9 @@ type transactionRequest struct {
}

type transactionCollectionsRequest struct {
Read []string `json:"read,omitempty"`
Write []string `json:"write,omitempty"`
Read []string `json:"read,omitempty"`
Write []string `json:"write,omitempty"`
Exclusive []string `json:"exclusive,omitempty"`
}

type transactionResponse struct {
Expand Down