Sails-ArangoJs

Sails-ArangoJs

  • Docs
  • API

›CRUD API

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

Let Method

Let Method

The method used to declare variables to be used later in a query statement. The Statment can be used later in the where, select and other places, using the $ sign.

Usage

const let = await Collection.let({
  Foo: "Bar",
}).find({
  Foo: "$FOO",
});

This Allows us to used ArangoDb Functions, For Example below we used the date functions. Note the use of the dollar sign when refering to the variable

const loans = await Loan.let({
  Diff: "DATE_DIFF(record.ApprovalDate, DATE_NOW(), 'months', true)",
})
  .find()
  .where({
    LoanStatus: "OUTSTANDING",
    $Diff: { $gt: "$record.PaidMonths" },
  });

You can also add the $ sign before record to tell js this is not a string value

Example

const count = await _Accounttransaction(dsName)
  .let({
    from: "$record._from",
  })
  .count({
    "FromAccount._id": { $ne: "$record._from" },
  });

This is translated to:

FOR record in accounttransaction
LET from = record._from

 FILTER record.FromAccount._id != record._from COLLECT WITH COUNT INTO length RETURN length

WITHOUT $ SIGN:

const count = await _Accounttransaction(dsName)
  .let({
    from: "record._from",
  })
  .count({
    "FromAccount._id": { $ne: "$record._from" },
  });

This is translated to:

    FOR record in accounttransaction
    LET from = 'record._from'

    FILTER record.FromAccount._id != record._from COLLECT WITH COUNT INTO length RETURN length

This is not the result we want.

IN OTHER WORDS JUST APPEND a $ sign of the value is NOT A STRING

$ SIGN INFRONT OF KEYS


const count = await _Accounttransaction(dsName)
.let({
from: '$record._from',
      })
      .count({
        '$FromAccount._id': { $ne: '$record._from' },
});

Translates:


FOR record in accounttransaction
LET from = record._from

 FILTER FromAccount._id != record._from COLLECT WITH COUNT INTO length RETURN length

Notice that FromAccount._id should have been rec.FromAccount._id

Happy Coding!!

← Testingcreate →
  • Let Method
    • Usage
  • WITHOUT $ SIGN:
  • $ SIGN INFRONT OF KEYS
Sails-ArangoJs
Docs
Getting StartedAPI Reference
Community
User ShowcaseStack OverflowTwitter
More
BlogGitHub
Cloudhub Developer Community
Copyright © 2022 Cloud Hub Limited