Sails-ArangoJs

Sails-ArangoJs

  • Docs
  • API

›Going Native

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

Going Native

You may want to use the arangojs driver directly without the absraction of the adapter. You can do so my importing the dbConnection object in your file.

For more information on arangojs, Visit the ArangoJs driver documentation.

Basic usage example

In the following exaple, we use the user model to import the dbConnection object in to our Controller file.

We can then use is normally as if we imported from arangojs


    // Modern JavaScript
    const { dbConnection, aql } = User.getDatastore().manager;
    (async function() {
    const now = Date.now();
    try {
        const cursor = await dbConnection.query(aql`
        RETURN ${now}
        `);
        const result = await cursor.next();
        // ...
    } catch (err) {
        // ...
    }
    })();


Executing a transaction

In SQL, transactions are started with explicit BEGIN or START TRANSACTION command. Following any series of data retrieval or modification operations, an SQL transaction is finished with a COMMIT command, or rolled back with a ROLLBACK command. There may be client/server communication between the start and the commit/rollback of an SQL transaction.

In ArangoDB, a transaction is always a server-side operation, and is executed on the server in one go, without any client interaction. All operations to be executed inside a transaction need to be known by the server when the transaction is started.

There are no individual BEGIN, COMMIT or ROLLBACK transaction commands in ArangoDB. Instead, a transaction in ArangoDB is started by providing a description of the transaction to the db._executeTransaction JavaScript function:

    const { dbConnection, aql } = User.getDatastore().manager;

    dbConnection._executeTransaction(description);

Transaction Example

The official driver documentation has more exmples and details on executing transactions in ArangoJs.


    const { dbConnection, aql } = User.getDatastore().manager;

    const action = String(function(params) {
    // This code will be executed inside ArangoDB!
    const { query } = require("@arangodb");
    return query`
        FOR user IN _users
        FILTER user.age > ${params.age}
        RETURN u.user
        `.toArray();
    });

    const result = await db.executeTransaction("_users", action, {
    params: { age: 12 }
    });
← GraphFoxx Services →
  • Basic usage example
  • Executing a transaction
    • Transaction Example
Sails-ArangoJs
Docs
Getting StartedAPI Reference
Community
User ShowcaseStack OverflowTwitter
More
BlogGitHub
Cloudhub Developer Community
Copyright © 2022 Cloud Hub Limited