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 |
* |
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> |
Returns:
documents - result documents
_generateLink(document) → {Link}
Generate Link from document by fields.
Parameters:
Name | Type | Description |
---|---|---|
document |
Object |
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> |
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> |
Returns:
links - result links objects in array
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> |
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> |
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 |
options(optionsopt) → {*}
Generate adapted for database options object.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
options |
Object |
<optional> |
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 |
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> |
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> |
Returns:
[count]
- Type
- number
Type Definitions
eachCallback(linkopt)
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
link |
Link |
<optional> |
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> |
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> |
mapCallback(linkopt) → {*}
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
link |
Link |
<optional> |
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 |
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> |
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> |