• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript arangojs.Database类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: drop

    drop: async function drop(): Promise<any> {
      await config.load(process.cwd() + '/test');
      const cfg = await config.get();

      const dbHost: string = cfg.get('database:arango:host');
      const dbPort: string = cfg.get('database:arango:port');
      const dbName: string = cfg.get('database:arango:database');

      const db = new Database('http://' + dbHost + ':' + dbPort);
      await db.dropDatabase(dbName);
    },
开发者ID:restorecommerce,项目名称:chassis-srv,代码行数:11,代码来源:database_test.ts


示例2: retry

    return await retry(async () => {
      logger.info('Attempt to connect database', {
        dbHost, dbPort, dbName,
        attempt: i
      });
      i += 1;
      const db = new Database({
        url,
        arangoVersion,
      });
      try {
        db.useDatabase(dbName);

        if (username && password) {
          db.useBasicAuth(username, password);
        }
        await db.get();
      } catch (err) {
        if (err.name === 'ArangoError' && err.errorNum === 1228) {
          if (autoCreate) {
            logger.verbose(`auto creating arango database ${dbName}`);
            // Database does not exist, create a new one
            db.useDatabase(DB_SYSTEM);
            await db.createDatabase(dbName);
            db.useDatabase(dbName);
            return db;
          }
        }
        throw err;
      }
      return db;
    }, { retries: attempts, minTimeout: delay });
开发者ID:restorecommerce,项目名称:chassis-srv,代码行数:32,代码来源:index.ts


示例3: 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


示例4: 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


示例5: 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


示例6: 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类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript arangojs.Graph类代码示例发布时间:2022-05-25
下一篇:
TypeScript AppState.ThunkResult类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap