本文整理汇总了TypeScript中arangojs.Graph.vertexCollection方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Graph.vertexCollection方法的具体用法?TypeScript Graph.vertexCollection怎么用?TypeScript Graph.vertexCollection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arangojs.Graph
的用法示例。
在下文中一共展示了Graph.vertexCollection方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getVertexCollection
/**
* gets a new GraphVertexCollection instance with the given name for this graph.
*
* @param {string} collectionName The handle of the vertex to retrieve.
* This can be either the _id or the _key of a vertex in the collection,
* or a vertex (i.e. an object with an _id or _key property).
* @return {Object} created vertex
*/
async getVertexCollection(collectionName: string): Promise<Object> {
if (_.isNil(collectionName)) {
throw new Error('missing vertex collection name');
}
const collection = await this.graph.vertexCollection(collectionName);
return collection;
}
示例2: getVertex
/**
* Retreives the vertex with the given documentHandle from the collection.
*
* @param {string} collectionName vertex collection name
* @param {string} documentHandle The handle of the vertex to retrieve.
* This can be either the _id or the _key of a vertex in the collection,
* or a vertex (i.e. an object with an _id or _key property).
* @return {Object} created vertex
*/
async getVertex(collectionName: string, documentHandle: string): Promise<Object> {
if (_.isNil(collectionName)) {
throw new Error('missing vertex collection name');
}
if (_.isNil(documentHandle)) {
throw new Error('missing document handle');
}
const collection = this.graph.vertexCollection(collectionName);
const doc = await collection.vertex(documentHandle);
return doc;
}
示例3: removeVertex
/**
* Deletes the vertex with the given documentHandle from the collection.
*
* @param {string} collectionName vertex collection name
* @param {string[]} documentHandles An array of the documentHandles to be removed.
* This can be either the _id or the _key of a vertex in the collection,
* or a vertex (i.e. an object with an _id or _key property).
* @return {Object} removed vertex
*/
async removeVertex(collectionName: string, documentHandles: string | string[]): Promise<any> {
if (_.isNil(collectionName)) {
throw new Error('missing vertex collection name');
}
if (_.isNil(documentHandles)) {
throw new Error('missing document handle property');
}
if (!_.isArray(documentHandles)) {
documentHandles = [documentHandles as string];
}
const collection = this.graph.vertexCollection(collectionName);
let removedVertexList = [];
for (let documentHandle of documentHandles) {
removedVertexList.push(await collection.remove(documentHandle));
}
if (removedVertexList.length === 1) {
return removedVertexList[0];
}
return removedVertexList;
}
示例4: createVertex
/**
* create a new Vertex with given data.
*
* @param {string} collectionName vertex collection name
* @param {Object} data data for vertex
* @return {Object} created vertex
*/
async createVertex(collectionName: string, data: any): Promise<any> {
if (_.isNil(collectionName)) {
throw new Error('missing vertex collection name');
}
if (_.isNil(data)) {
throw new Error('missing data for vertex');
}
const collection = this.graph.vertexCollection(collectionName);
let docs = _.cloneDeep(data);
if (!_.isArray(docs)) {
docs = [docs];
}
_.forEach(docs, (document, i) => {
docs[i] = sanitizeInputFields(document);
});
const results = await collection.save(docs);
_.forEach(results, (result) => {
if (result.error === true) {
throw new Error(result.errorMessage);
}
});
return _.map(docs, sanitizeOutputFields);
}