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
30 changes: 27 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -915,10 +915,34 @@ Performs a server-side transaction and returns its return value.
Available as variable `params` when the _action_ function is being executed on
server. Check the example below.

* **lockTimeout**: `number` (optional)
* **options**: `Object|number` (optional)

For backwards compatability, the options object can either be a `number` denoting
a `lockTimeout` or an options option containing the following properties, as per the
[the HTTP API documentation for transactions](https://docs.arangodb.com/latest/HTTP/Transaction/index.html):

Determines how long the database will wait while attemping to gain locks on
collections used by the transaction before timing out.
* **lockTimeout**: `number` (optional)

Determines how long the database will wait while attemping to gain locks on
collections used by the transaction before timing out.

* **waitForSync**: `boolean` (optional)

Determines whether to force the transaction to write all data to disk before returning.

* **maxTransactionSize**: `number` (optional)

Determines the transaction size limit in bytes. Honored by the RocksDB storage engine only.

* **intermediateCommitCount**: `number` (optional)

Determines the maximum number of operations after which an intermediate commit is
performed automatically. Honored by the RocksDB storage engine only.

* **intermediateCommitSize**: `number` (optional)

Determine the maximum total size of operations after which an intermediate commit is
performed automatically. Honored by the RocksDB storage engine only.

If _collections_ is an array or string, it will be treated as
_collections.write_.
Expand Down
29 changes: 25 additions & 4 deletions src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ export type TransactionCollections = {
};
export type TrCols = CollectionName | CollectionName[] | TransactionCollections;

export type TransactionOptions = {
lockTimeout?: number,
maxTransactionSize?: number,
intermediateCommitCount?: number,
intermediateCommitSize?: number,
waitForSync?: boolean
};

export type TrOptions = number | TransactionOptions;

export type ServiceOptions = {
[key: string]: any;
configuration?: { [key: string]: any };
Expand Down Expand Up @@ -180,16 +190,27 @@ export class Database {
collections: CollectionName | CollectionName[] | TransactionCollections,
action: string,
params?: any,
lockTimeout?: number
options?: TrOptions
): Promise<any>;
async transaction(
collections: CollectionName | CollectionName[] | TransactionCollections,
action: string,
params?: any,
lockTimeout?: number
options?: TrOptions
): Promise<any> {
if (typeof params === "number") {
lockTimeout = params;
options = { lockTimeout: params };
params = undefined;
}
if (
typeof params === "object"
&& (params.waitForSync
|| params.lockTimeout
|| params.maxTransactionSize
|| params.intermediateCommitCount
|| params.intermediateCommitSize)
) {
options = params;
params = undefined;
}
if (typeof collections === "string") {
Expand All @@ -215,7 +236,7 @@ export class Database {
collections,
action,
params,
lockTimeout
...(options as TransactionOptions)
});
return res.body.result;
}
Expand Down