ObjectGraph

ObjectGraph

Inherited class. Class with methods for control links in graph. Adapted for array collection.

Constructor

new ObjectGraph(collection, fields, configopt)

import { ObjectGraph as Graph } from 'ancient-graph';

Source:
Parameters:
Name Type Attributes Description
collection Array.<Array>
fields Object.<string, string>

matching of fields in the link with fields in document

config Object <optional>

Additional config.

Name Type Attributes Description
aliases Object <optional>
Name Type Attributes Description
$ String <optional>

Methods

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

Fetch native database documents.

Source:
Parameters:
Name Type Attributes Description
selector string | linkSelector
options SelectOptions <optional>
Returns:
Type:
Array.<Object>

documents - result documents

Generate Link from document by fields.

Source:
Parameters:
Name Type Description
document Object
Returns:
Type:
Link

link

_idGenerator(index, link) → {number|string}

Specifies the id field on insert

Source:
Parameters:
Name Type Description
index number
link Link
Returns:
Type:
number | string

id;

_insertModifier(index, link) → {number|string}

Generate insert modifier.

Source:
Parameters:
Name Type Description
index number
link Link
Returns:
Type:
number | string

id;

_updateModifier(modifier, result) → {number|string}

Generate update modifier.

Source:
Parameters:
Name Type Description
modifier LinkModifier
result Object
Returns:
Type:
number | string

id;

_updateModifierAdd(data, item)

Push into link value some item/items if not already exists.

Source:
Parameters:
Name Type Description
data Array
item string | number | Array.<string> | Array.<number>

_updateModifierPush(data, item)

Push into link value some item/items.

Source:
Parameters:
Name Type Description
data Array
item string | number | Array.<string> | Array.<number>

_updateModifierRemove(data, item)

Remove from link value some item/items.

Source:
Parameters:
Name Type Description
data Array
item string | number | Array.<string> | Array.<number>

count(selector, optionsopt, callbackopt) → {number}

Count all matching documents.

Source:
Parameters:
Name Type Attributes Description
selector string | LinkSelector
options SelectOptions <optional>
callback Graph~countCallback <optional>
Returns:
Type:
number

[count]

each(selector, optionsopt, callbackopt)

Should call callback once for each matching document, sequentially and synchronously.

Source:
Parameters:
Name Type Attributes Description
selector string | LinkSelector
options SelectOptions <optional>
callback Graph~eachCallback <optional>

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

Find and all matching links as an Array.

Source:
Parameters:
Name Type Attributes Description
selector string | LinkSelector
options SelectOptions <optional>
callback Graph~fetchCallback <optional>
Returns:
Type:
Array.<Link>

links - result links objects in array

get(selector, optionsopt, callbackopt) → {Link}

Get one first matching link.

Source:
Parameters:
Name Type Attributes Description
selector string | LinkSelector
options SelectOptions <optional>
callback Graph~getCallback <optional>
Returns:
Type:
Link

link - result link object

insert(link, callbackopt, contextopt) → {number|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.

Source:
Parameters:
Name Type Attributes Description
link Link
callback Graph~insertCallback <optional>
context Object <optional>
Returns:
Type:
number | string

[id]

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

Map callback over all matching documents. Returns an Array.

Source:
Parameters:
Name Type Attributes Description
selector string | LinkSelector
options SelectOptions <optional>
callback Graph~mapCallback <optional>
Returns:
Type:
Array

results

on(event, callback) → {function}

Should subscribe to the events: link, unlink, insert, update, remove.

Source:
Parameters:
Name Type Description
event string

One event name

callback Graph~onCallback
Returns:
Type:
function

Stops event subscription.

Example
var counter = 0;
var stop = graph.on('update', (oldData, newData) => {
  if (oldData.id == '1') console.log(oldData.id, 'is changed');
  counter++;
  if (counter == 3) stop();
});

options(optionsopt) → {*}

Generate adapted for database options object.

Source:
Parameters:
Name Type Attributes Description
options Object <optional>
Returns:
Type:
*

options - a options suitable for the database

query(selector) → {*}

Generate adapter for database query for links search by unique id or by link query object.

Source:
Parameters:
Name Type Description
selector string | LinkSelector
Returns:
Type:
*

query

remove(selector, callbackopt, contextopt)

Should remove link by unique id or by link query object.

Source:
Parameters:
Name Type Attributes Description
selector string | LinkSelector
callback Graph~removeCallback <optional>
context Object <optional>

update(selector, modifier, callbackopt, contextopt) → {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.

Source:
Parameters:
Name Type Attributes Description
selector string | LinkSelector
modifier LinkModifier
callback Graph~updateCallback <optional>
context Object <optional>
Returns:
Type:
number

[count]