当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Database.collection方法代码示例

本文整理汇总了TypeScript中arangojs.Database.collection方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Database.collection方法的具体用法?TypeScript Database.collection怎么用?TypeScript Database.collection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在arangojs.Database的用法示例。


在下文中一共展示了Database.collection方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: truncate

 /**
  * When calling without a collection name,
  * delete all documents in all collections in the database.
  * When providing a collection name,
  * delete all documents in specified collection in the database.
  * @param [string] collection Collection name.
  */
 async truncate(collection: string): Promise<any> {
   if (_.isNil(collection)) {
     const collections = await this.db.collections();
     for (let i = 0; i < collections.length; i += 1) {
       const c = this.db.collection(collections[i].name);
       await c.truncate();
     }
   } else {
     const c = this.db.collection(collection);
     await c.truncate();
   }
 }
开发者ID:restorecommerce,项目名称:chassis-srv,代码行数:19,代码来源:base.ts

示例2: update

 /**
  * Find documents by filter and updates them with document.
  *
  * @param  {String} collection Collection name
  * @param  {Object} filter     Key, value Object
  * @param  {Object} document  A document patch.
  */
 async update(collectionName: string, filter: any, document: any): Promise<any> {
   if (_.isNil(collectionName) ||
     !_.isString(collectionName) || _.isEmpty(collectionName)) {
     throw new Error('invalid or missing collection argument');
   }
   if (_.isNil(document)) {
     throw new Error('invalid or missing document argument');
   }
   const doc = sanitizeInputFields(_.clone(document));
   const collection = this.db.collection(collectionName);
   let queryString = aql`FOR node in ${collection}
     FILTER node.id == ${doc.id}
     UPDATE node WITH ${doc} in ${collection} return NEW`;
   const res = await query(this.db, collectionName, queryString);
   const upDocs = await res.all();
   return _.map(upDocs, sanitizeOutputFields);
 }
开发者ID:restorecommerce,项目名称:chassis-srv,代码行数:24,代码来源:base.ts

示例3: insert

 /**
  * Insert documents into database.
  *
  * @param  {String} collection Collection name
  * @param  {Object|array.Object} documents  A single or multiple documents.
  */
 async insert(collectionName: string, documents: any): Promise<any> {
   if (_.isNil(collectionName) || !_.isString(collectionName) || _.isEmpty(collectionName)) {
     throw new Error('invalid or missing collection argument');
   }
   if (_.isNil(documents)) {
     throw new Error('invalid or missing documents argument');
   }
   let docs = _.cloneDeep(documents);
   if (!_.isArray(documents)) {
     docs = [documents];
   }
   _.forEach(docs, (document, i) => {
     docs[i] = sanitizeInputFields(document);
   });
   const collection = this.db.collection(collectionName);
   const queryTemplate = aql`FOR document in ${docs} INSERT document INTO ${collection}`;
   await query(this.db, collectionName, queryTemplate);
 }
开发者ID:restorecommerce,项目名称:chassis-srv,代码行数:24,代码来源:base.ts

示例4: upsert

  /**
   * Find each document based on it's key and update it.
   * If the document does not exist it will be created.
   *
   * @param  {String} collection Collection name
   * @param {Object|Array.Object} documents
   */
  async upsert(collectionName: string, documents: any): Promise<any> {
    if (_.isNil(collectionName) ||
      !_.isString(collectionName) || _.isEmpty(collectionName)) {
      throw new Error('invalid or missing collection argument');
    }
    if (_.isNil(documents)) {
      throw new Error('invalid or missing documents argument');
    }
    let docs = _.cloneDeep(documents);
    if (!_.isArray(documents)) {
      docs = [documents];
    }
    _.forEach(docs, (document, i) => {
      docs[i] = sanitizeInputFields(document);
    });
    const collection = this.db.collection(collectionName);
    const queryTemplate = aql`FOR document in ${docs} UPSERT { _key: document._key }
      INSERT document UPDATE document IN ${collection} return NEW`;

    const res = await query(this.db, collectionName, queryTemplate);
    const newDocs = await res.all();
    return _.map(newDocs, sanitizeOutputFields);
  }
开发者ID:restorecommerce,项目名称:chassis-srv,代码行数:30,代码来源:base.ts


注:本文中的arangojs.Database.collection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。