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

Graph

graph databases methods:

MethodStatusCategory
createEdgeDoneDML
findAnyDoneDQL
findInboundDoneDQL
findOutboundDoneDQL

createEdge Method

The following is an example of creating an edge.


   const edgeproperties = {
        Year: 2008,
        Month: 1,
        Day: 1,
        DayOfWeek: 2,
        DepTime: 644,
        ArrTime: 866,
        DepTimeUTC: '2008-01-01T11:04:00.000Z',
        ArrTimeUTC: '2008-01-01T13:06:00.000Z',
        UniqueCarrier: '9E',
        FlightNum: 2938,
        TailNum: '87979E',
        Distance: 444,
      };

      const from_id = 'airport/00M';
      const to_id = 'airport/00R';

      Flight.createEdge(
        edgeproperties,
        {
          from: from_id,
          to: to_id,
        },
        (err, edge) => {
          if (err) {
            return done(err);
          }

          assert.equal(edge._from, `${from_id}`);
          assert.equal(edge._to, `${to_id}`);
      })

findAny, findInbound, findOutbound Methods

The following is an example of getting vertices connecting to a node. If graph if not set to true in the datastore config, You will have to supply the edgeCollctions array arributo of the the ANONYMOUS graph. Otherwise you dont have to.

     //Flights connecting from an airport
     const airports = await Airport.findOutbound('00M', ['flights]);

     // or

    //Flights connecting to or from an airport
    const airports = await Airport.findAny(['00M', ['flights]);

Query graph

     //Flights connecting from an airport
     const airports = await Airport.findOutbound('00M');

     // or

    //Flights connecting to an airport
    const airports = await Airport.findInbound('00M');

     // or
    //Flights connecting to or from an airport
    const airports = await Airport.findAny('00M');

the above will return an array of nodes and edges. [{vertex: {...}, edge:{...}}, ...]

.whereVertex({...}) and whereEdge({...}) methods

You can filter Vertices and Edges using .whereVertex({...}) and whereEdge({...}) methods.

  const airports = await Airport.findAny('00M').whereVertex({VIP: true}).whereEdge({FlightNum: 2938});

Sorting

You can sort just like in any model, but you have to let the adapter know if its edge or å sorting

const airports = await Airport.findAny('00M').sort('edge.FlightNum')

← Implementing transacationsNative Methods →
  • graph databases methods:
  • createEdge Method
  • findAny, findInbound, findOutbound Methods
  • Query graph
  • .whereVertex({...}) and whereEdge({...}) methods
  • Sorting
Sails-ArangoJs
Docs
Getting StartedAPI Reference
Community
User ShowcaseStack OverflowTwitter
More
BlogGitHub
Cloudhub Developer Community
Copyright © 2022 Cloud Hub Limited