Sails-ArangoJs

Sails-ArangoJs

  • Docs
  • API

›Graph & Transactions

Getting Started

  • Installation
  • Creating Models
  • Testing

CRUD API

  • let
  • create
  • createEach
  • update
  • updateOne
  • upsert
  • find
  • findOne
  • sum
  • avg
  • destroy
  • count
  • aggregate
  • sample
  • findNear
  • findWithCount

Graph & Transactions

  • Implementing transacations
  • Graph

Going Native

  • Native Methods
  • Foxx Services

Transactions

These functions implement the ArangoDB HTTP API for JS transactions. Also see ArangoDB Transactions.

Importance of transactions

ArangoDB provides support for user-definable transactions.

Transactions in ArangoDB are atomic, consistent, isolated, and durable (ACID).

These ACID properties provide the following guarantees:

The atomicity principle makes transactions either complete in their entirety or have no effect at all.

The consistency principle ensures that no constraints or other invariants will be violated during or after any transaction. A transaction will never corrupt the database.

The isolation property will hide the modifications of a transaction from other transactions until the transaction commits.

Finally, the durability proposition makes sure that operations from transactions that have committed will be made persistent.

The amount of transaction durability is configurable in ArangoDB, as is the durability on collection level. Should you run the ArangoDB Cluster, please see the Limitations section to see more details regarding transactional behavior of multi-document transactions in a distributed systems.

Implementing a transaction

To implement a transaction, Sails-ArangoJs abstracts the implementation to make it easy and faster to write a transaction code.

Example

     const paymenttransaction = await Transaction({
          action: function(params) {
            // save transaction
            const user = db.user.document(params.userid);

            const timestamp = new Date().getTim
            //control account transaction
            db.payment.insert({
             ...params
             email: user.email
            });

            return {...object};
          },
          writes: [
            'payment',
            .
            .
            .
          ],
          reads: ['user']  //optional
          params: {
            userid: '1288676'
          },
          {...other options}
        });

Client side transactions

You may also want to execute transaction on the client side code.

 const trx = await dbConnection.beginTransaction({
        // read: ['vertices'],
        write: ['account', 'tx'], // collection instances can be passed directly
      });

      let acs;

      try {


         acs = await Account.create({ _key: '5555', Name: 'John' }).meta({
           fetch: true,
           trx,
         });


         acs = await Account.destroy({
           createdAt: { $gt: Date.now() },
         }).meta({
           trx,
           fetch: true,
         });

        await trx.commit();
      } catch (error) {
        await trx.abort();
        throw error;
      }


← findWithCountGraph →
  • Importance of transactions
  • Implementing a transaction
    • Example
  • Client side transactions
Sails-ArangoJs
Docs
Getting StartedAPI Reference
Community
User ShowcaseStack OverflowTwitter
More
BlogGitHub
Cloudhub Developer Community
Copyright © 2022 Cloud Hub Limited