arangodb / arangojs

The official ArangoDB JavaScript driver.
https://arangodb.github.io/arangojs
Apache License 2.0
600 stars 106 forks source link

Can someone provide me with a very basic example of working with Graphs? #716

Closed enjoysmath closed 2 years ago

enjoysmath commented 3 years ago

I can't find example code anywhere on the net and I'm new to JS, so parsing the source code and reverse engineering is too difficult for now.

For example, is the following the proper way?

try {
  graph = db.createGraph('school', [], []);
}
catch (err)
{
  console.log(err);
  graph = db.graph('school');
}
pluma commented 2 years ago

Assuming you want to create a graph if it doesn't already exist and then do something with it, I'd do it like this:

const graph = db.graph("school");
if (!(await graph.exists())) {
  /* possibly create collections for the graph and populate them here */
  await graph.create(/* graph definition goes here */);
}
// graph now exists and can be used

It looks like you're looking for help with using graphs in general, not specifically how to use the driver though, so I'd recommend checking out the community slack: https://slack.arangodb.com