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


TypeScript arangojs.Database类代码示例

本文整理汇总了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;未经允许,请勿转载。