Graph

Graph

new Graph(collection, fields)

Construct new graph and checks for required adaptation methods.
Parameters:
Name Type Description
collection Mongo.Collection
fields Object matching of fields in the link with fields in document
object.source *
object.target *
Source:
Throws:
if the adapter methods is not complete
Type
Error

Methods

_find(selector, optionsopt) → {Array:.<Object:>}

Fetch native database documents.
Parameters:
Name Type Attributes Description
selector string | linkSelector
options SelectOptions <optional>
Source:
Returns:
documents - result documents
Type
Array:.<Object:>
Generate Link from document by fields.
Parameters:
Name Type Description
document Object
Source:
Returns:
link
Type
Link

each(selector, optionsopt, callbackopt)

Should call callback once for each matching document, sequentially and synchronously.
Parameters:
Name Type Attributes Description
selector string | LinkSelector
options SelectOptions <optional>
callback Graph~eachCallback <optional>
Source:

fetch(selector, optionsopt, callbackopt) → {Array:.<Link:>}

Find and all matching links as an Array.
Parameters:
Name Type Attributes Description
selector string | LinkSelector
options SelectOptions <optional>
callback Graph~fetchCallback <optional>
Source:
Returns:
links - result links objects in array
Type
Array:.<Link:>

insert(link, callbackopt) → {string}

Should insert new link into graph. Return a synchronous result. This can be useful in your application. But for writing generic code, it is recommended to only use the callback result.
Parameters:
Name Type Attributes Description
link Link
callback Graph~insertCallback <optional>
Source:
Returns:
[id]
Type
string

map(selector, optionsopt, callbackopt) → {Array}

Should map callback over all matching documents. Returns an Array.
Parameters:
Name Type Attributes Description
selector string | LinkSelector
options SelectOptions <optional>
callback Graph~mapCallback <optional>
Source:
Returns:
results
Type
Array

on(event, callback)

Should subscribe to the events: link, unlink, insert, update, remove.
Parameters:
Name Type Description
event string name
callback Graph-onCallback
Source:

options(optionsopt) → {*}

Generate adapted for database options object.
Parameters:
Name Type Attributes Description
options Object <optional>
Source:
Returns:
options - a options suitable for the database
Type
*

query(selector) → {*}

Generate adapter for database query for links search by unique id or by link query object.
Parameters:
Name Type Description
selector string | LinkSelector
Source:
Returns:
query
Type
*

remove(selector, callbackopt)

Should remove link by unique id or by link query object.
Parameters:
Name Type Attributes Description
selector string | LinkSelector
callback Graph~removeCallback <optional>
Source:

update(selector, modifier, callbackopt) → {number}

Should update to new state of modifier object link by unique id or by link query object. If the database allows, it is recommended to return a synchronous result. This can be useful in your application. But for writing generic code, it is recommended to only use the callback result.
Parameters:
Name Type Attributes Description
selector string | LinkSelector
modifier LinkModifier
callback Graph~updateCallback <optional>
Source:
Returns:
[count]
Type
number

Type Definitions

eachCallback(linkopt)

Parameters:
Name Type Attributes Description
link Link <optional>
Source:

fetchCallback(erroropt, linksopt)

Optional callback. If present, called with an error object as the first argument and, if no error, the result links objects in array.
Parameters:
Name Type Attributes Description
error Error <optional>
links Array:.<Link:> <optional>
Source:

insertCallback(erroropt, idopt)

Optional callback. If present, called with an error object as the first argument and, if no error, the unique id of inserted link as the second.
Parameters:
Name Type Attributes Description
error Error <optional>
id string <optional>
Source:

mapCallback(linkopt) → {*}

Parameters:
Name Type Attributes Description
link Link <optional>
Source:
Returns:
result
Type
*

onCallback(oldLinkopt, newLinkopt, contextopt)

Parameters:
Name Type Attributes Description
oldLink Link <optional>
can be undefined on link and insert events
newLink Link <optional>
can be undefined on unlink and remove events
context Object <optional>
additional app information, such as context.userId
Source:

removeCallback(erroropt, countopt)

Optional callback. If present, called with an error object as the first argument.
Parameters:
Name Type Attributes Description
error Error <optional>
count number <optional>
Source:

updateCallback(erroropt, countopt)

Optional callback. If present, called with an error object as the first argument and, if no error, the number of affected documents as the second.
Parameters:
Name Type Attributes Description
error Error <optional>
count number <optional>
Source: