GraphDB Utils API
Classes
Functions
- createGraphDBModel(schema, schemaOptions) โ GraphDBModel |
function
Typedefs
GraphDBDocument
Kind: global class
- GraphDBDocument
- .data โ
Object - .schema โ
Object - .schemaOptions โ
GDSchemaOptions - .get(path) โ
undefined|GraphDBDocument|string|number|boolean - .set(path, obj) โ
undefined|GraphDBDocument|string|number|boolean - .markModified(key)
- .populate(path) โ Promise.<GraphDBDocument>
- .toJSON() โ
object
- .data โ
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
| Param | Type |
|---|---|
| path | string |
Example
graphDBDocument.set(path, obj) โ undefined | GraphDBDocument | string | number | boolean
Set a property of the document using path.
Kind: instance method of GraphDBDocument
| Param | Type |
|---|---|
| path | string |
| obj | * |
Example
graphDBDocument.markModified(key)
Kind: instance method of GraphDBDocument
| Param | Type | Description |
|---|---|---|
| key | Array.<string> | string | The external key to mark modified. |
graphDBDocument.populate(path) โ Promise.<GraphDBDocument>
Populate a field by path, and return this GraphDBDocument.
Kind: instance method of GraphDBDocument
| Param | Type | Description |
|---|---|---|
| path | string | Path 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
- GraphDBDocumentArray โ
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
| Param | Type | Description |
|---|---|---|
| path | string | e.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
| Param | Type | Description |
|---|---|---|
| paths | Array.<string> | e.g. ['primary_contact', 'organization'] |
GraphDBModel
Kind: global class
- GraphDBModel
- new GraphDBModel(data)
- .createDocument(data) โ
GraphDBDocument - .generateCreationQuery(id, data) โ Promise.<{footer: string, instanceName: string, innerQueryBodies: Array.<string>, header: string, queryBody: string}>
- .findById(id, options) โ Promise.<GraphDBDocument>
- .findOne(filter, [options]) โ Promise.<GraphDBDocument>
- .findOneAndUpdate(filter, update) โ Promise.<GraphDBDocument>
- .findByIdAndUpdate(id, update) โ Promise.<GraphDBDocument>
- .findOneAndDelete(filter) โ Promise.<GraphDBDocument>
- .findByIdAndDelete(id) โ Promise.<GraphDBDocument>
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
| Param | Type | Description |
|---|---|---|
| data | object | The 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
| Param | Type | Description |
|---|---|---|
| data | object | The 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
| Param | Type |
|---|---|
| id | number | 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
| Param | Type | Description |
|---|---|---|
| id | string | number | ID of the document, usually represents as _id |
| options | Object |
Example
graphDBModel.findOne(filter, [options]) โ Promise.<GraphDBDocument>
Find one document in the model.
Kind: instance method of GraphDBModel
See: GraphDBModel.find for further information
| Param | Type | Description |
|---|---|---|
| filter | Object | The filter |
| [options] | Object |
Example
graphDBModel.findOneAndUpdate(filter, update) โ Promise.<GraphDBDocument>
Find one document and update.
Kind: instance method of GraphDBModel
| Param | Type | Description |
|---|---|---|
| filter | Object | The filter |
| update | Object | The Update to the found document |
Example
graphDBModel.findByIdAndUpdate(id, update) โ Promise.<GraphDBDocument>
Find one document by ID and update
Kind: instance method of GraphDBModel
| Param | Type | Description |
|---|---|---|
| id | string | number | The identifier |
| update | Object | The Update to the found document |
Example
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.
| Param | Type | Description |
|---|---|---|
| filter | Object | The filter |
Example
graphDBModel.findByIdAndDelete(id) โ Promise.<GraphDBDocument>
Find one document by ID and delete it.
Kind: instance method of GraphDBModel
Returns: Promise.<GraphDBDocument> - - The deleted document.
| Param | Type | Description |
|---|---|---|
| id | string | number | The identifier |
Example
createGraphDBModel(schema, schemaOptions) โ GraphDBModel | function
Kind: global function
| Param | Type | Description |
|---|---|---|
| schema | object.<string, (GraphDBPropertyOptions|String|Number|Date|NamedIndividual|Boolean)> | GraphDBPropertyOptions |
| schemaOptions | SchemaOptions |
SchemaOptions
Kind: global typedef
Properties
| Name | Type | Description |
|---|---|---|
| name | string | The prefix of the created documents' identifier. e.g. if name="primary_contact", the new created document will have id :primary_contact_1 |
| rdfTypes | Array.<string> | The list of value in rdf:type. e.g. [Types.NamedIndividual, ":primary_contact"] => some_instance rdf:type owl:NamedIndividual, :primary_contact. |
Example
GraphDBPropertyOptions
Kind: global typedef
Properties
| Name | Type | Default | Description |
|---|---|---|---|
| type | String | Number | Date | NamedIndividual | Boolean | Data 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] | string | null | The internal key, internal keys are used in GraphDB, |
| [externalKey] | string | null | The 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. |