GraphDB Utils API

Classes

GraphDBDocument
GraphDBDocumentArray โ‡ Array
GraphDBModel

Functions

createGraphDBModel(schema, schemaOptions) โ‡’ GraphDBModel | function

Typedefs

SchemaOptions
GraphDBPropertyOptions

GraphDBDocument

Kind: global class

graphDBDocument.data โ‡’ Object

Get the document data.

Kind: instance property of GraphDBDocument

graphDBDocument.schema โ‡’ Object

Get the document's model schema.

Kind: instance property of GraphDBDocument

graphDBDocument.schemaOptions โ‡’ GDSchemaOptions

Get the document's model schemaOptions.

Kind: instance property of GraphDBDocument

graphDBDocument.get(path) โ‡’ undefined | GraphDBDocument | string | number | boolean

Get a property of the document using path.

Kind: instance method of GraphDBDocument

ParamType
pathstring

Example

`doc.get('organization.primary_contact')`

graphDBDocument.set(path, obj) โ‡’ undefined | GraphDBDocument | string | number | boolean

Set a property of the document using path.

Kind: instance method of GraphDBDocument

ParamType
pathstring
obj*

Example

`doc.get('organization.primary_contact')`

graphDBDocument.markModified(key)

Kind: instance method of GraphDBDocument

ParamTypeDescription
keyArray.<string> | stringThe external key to mark modified.

graphDBDocument.populate(path) โ‡’ Promise.<GraphDBDocument>

Populate a field by path, and return this GraphDBDocument.

Kind: instance method of GraphDBDocument

ParamTypeDescription
pathstringPath to the field that will be populated, i.e. account.primary_contact

graphDBDocument.toJSON() โ‡’ object

Override default JSON.stringify behavior.

Kind: instance method of GraphDBDocument

GraphDBDocumentArray โ‡ Array

Kind: global class
Extends: Array

new GraphDBDocumentArray()

Performance optimized for multiple populates.

graphDBDocumentArray.populate(path) โ‡’ Promise.<GraphDBDocumentArray>

populate a single property for every document.

Kind: instance method of GraphDBDocumentArray

ParamTypeDescription
pathstringe.g. 'primary_contact'

graphDBDocumentArray.populateMultiple(paths) โ‡’ Promise.<GraphDBDocumentArray>

Populate multiple properties for every document. Breadth first populate for combining queries.

Kind: instance method of GraphDBDocumentArray

ParamTypeDescription
pathsArray.<string>e.g. ['primary_contact', 'organization']

GraphDBModel

Kind: global class

new GraphDBModel(data)

Create a document based on the model. Note: The constructor does not comply OOP since it is dynamically generated. Same as GraphDBModel.createDocument

ParamTypeDescription
dataobjectThe data / properties in the new document

graphDBModel.createDocument(data) โ‡’ GraphDBDocument

Create a document based on the model. Identical to Model(data)

Kind: instance method of GraphDBModel

ParamTypeDescription
dataobjectThe data / properties in the new document

graphDBModel.generateCreationQuery(id, data) โ‡’ Promise.<{footer: string, instanceName: string, innerQueryBodies: Array.<string>, header: string, queryBody: string}>

Generate creation query.

Kind: instance method of GraphDBModel

ParamType
idnumber | string
data

graphDBModel.findById(id, options) โ‡’ Promise.<GraphDBDocument>

Find an document by ID in the model.

Kind: instance method of GraphDBModel
See: GraphDBModel.find for further information

ParamTypeDescription
idstring | numberID of the document, usually represents as _id
optionsObject

Example

// Same as
(await Model.find({_id: id}, {populates}))[0];
// Find one document with _id = 1 and populate
Model.findById(1, {populates: ['primary_contact']});

graphDBModel.findOne(filter, [options]) โ‡’ Promise.<GraphDBDocument>

Find one document in the model.

Kind: instance method of GraphDBModel
See: GraphDBModel.find for further information

ParamTypeDescription
filterObjectThe filter
[options]Object

Example

// Same as
await (Model.find(filter, {populates}))[0];
// Find one document and populate
Model.findOne({age: 50}, {populates: ['primary_contact']});

graphDBModel.findOneAndUpdate(filter, update) โ‡’ Promise.<GraphDBDocument>

Find one document and update.

Kind: instance method of GraphDBModel

ParamTypeDescription
filterObjectThe filter
updateObjectThe Update to the found document

Example

// Find a document has _id = 1 and update the primary_contact.first_name to 'Lester'
// The document has smaller id will be updated if it finds multiple matched documents.
const doc = await Model.findOneAndUpdate({_id: 1}, {primary_contact: {first_name: 'Lester'}});

graphDBModel.findByIdAndUpdate(id, update) โ‡’ Promise.<GraphDBDocument>

Find one document by ID and update

Kind: instance method of GraphDBModel

ParamTypeDescription
idstring | numberThe identifier
updateObjectThe Update to the found document

Example

// Find a document has id = 1 and update the primary_contact.first_name to 'Lester'
const doc = await Model.findByIdAndUpdate(1, {primary_contact: {first_name: 'Lester'}});

graphDBModel.findOneAndDelete(filter) โ‡’ Promise.<GraphDBDocument>

Find one document matched to the filter and delete.

Kind: instance method of GraphDBModel
Returns: Promise.<GraphDBDocument> - - The deleted document.

ParamTypeDescription
filterObjectThe filter

Example

// Find one document have primary_contact.first_name equal to 'Lester' and delete it.
// The document with smaller id will be deleted if found multiple documents.
const doc = await Model.findOneAndDelete({primary_contact: {first_name: 'Lester'}});

graphDBModel.findByIdAndDelete(id) โ‡’ Promise.<GraphDBDocument>

Find one document by ID and delete it.

Kind: instance method of GraphDBModel
Returns: Promise.<GraphDBDocument> - - The deleted document.

ParamTypeDescription
idstring | numberThe identifier

Example

// Find one document has id 1 and delete it.
const doc = await Model.findByIdAndDelete(1);

createGraphDBModel(schema, schemaOptions) โ‡’ GraphDBModel | function

Kind: global function

ParamTypeDescription
schemaobject.<string, (GraphDBPropertyOptions|String|Number|Date|NamedIndividual|Boolean)>GraphDBPropertyOptions
schemaOptionsSchemaOptions

SchemaOptions

Kind: global typedef
Properties

NameTypeDescription
namestringThe prefix of the created documents' identifier. e.g. if name="primary_contact", the new created document will have id :primary_contact_1
rdfTypesArray.<string>The list of value in rdf:type. e.g. [Types.NamedIndividual, ":primary_contact"] => some_instance rdf:type owl:NamedIndividual, :primary_contact.

Example

{name: 'primary_contact', rdfTypes: [Types.NamedIndividual, ':primary_contact']}

GraphDBPropertyOptions

Kind: global typedef
Properties

NameTypeDefaultDescription
typeString | Number | Date | NamedIndividual | BooleanData type,
[prefix]string"has_"The prefix add to each predicate,
[suffix]string"s"For array datatype only, the suffix append to the external key,
[internalKey]stringnullThe internal key, internal keys are used in GraphDB,
[externalKey]stringnullThe external key, external keys are used in javascript. (documents, filters, populates)
[onDelete]string"DeleteType.NON_CASCADE"The delete operation on nested models, default to non cascade.