當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript LevelUp.batch方法代碼示例

本文整理匯總了TypeScript中levelup.LevelUp.batch方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript LevelUp.batch方法的具體用法?TypeScript LevelUp.batch怎麽用?TypeScript LevelUp.batch使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在levelup.LevelUp的用法示例。


在下文中一共展示了LevelUp.batch方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: buildExistingFilesDb

  public async buildExistingFilesDb(watchPath: string): Promise<number> {
    try {
      const cwd = watchPath;

      const files = await globPromise(`**/*`, {
        cwd
      });

      const filePayload: FilePayload = {
        jobStatus: FileJobStatus.Existing,
        jobType: FileJobType.Unknown
      };

      const existingFiles = files.map(
        (filepath: string): AbstractBatch => ({
          key: path.resolve(cwd, filepath),
          type: 'put',
          value: filePayload
        })
      );

      await this.files.batch(existingFiles);

      return existingFiles.length;
    } catch (error) {
      throw error;
    }
  }
開發者ID:mshick,項目名稱:arrivals-osx,代碼行數:28,代碼來源:dispatcher.ts

示例2: addKeys

 async addKeys(params: {
   name: string;
   keys: Wallet.KeyImport[];
   encryptionKey: string;
 }) {
   const { name, keys, encryptionKey } = params;
   const ops = keys.map(key => {
     let { pubKey } = key;
     pubKey =
       pubKey || new bitcoreLib.PrivateKey(key.privKey).publicKey.toString();
     let payload = {};
     if (pubKey && key.privKey && encryptionKey) {
       const encKey = Encryption.encryptPrivateKey(
         JSON.stringify(key),
         Buffer.from(pubKey, 'hex'),
         Buffer.from(encryptionKey, 'hex')
       );
       payload = { encKey, pubKey };
     }
     return {
       type: 'put',
       key: `key|${name}|${key.address}`,
       value: JSON.stringify(payload)
     };
   });
   if (ops.length > 1) {
     return this.db.batch(ops);
   } else {
     this.db.put(ops[0].key, ops[0].value);
   }
 }
開發者ID:bitpay,項目名稱:bitcore,代碼行數:31,代碼來源:storage.ts

示例3: callback

 this.get(null, data => {
   const batch = this.db.batch();
   for (const key in data) {
     batch.del(key);
   }
   batch.write(() => {
     callback();
   });
 });
開發者ID:laquereric,項目名稱:wexond,代碼行數:9,代碼來源:storage-area.ts

示例4: set

  public set(items: any, callback: any) {
    if (items === Object(items)) {
      const batch = this.db.batch();

      for (const key in items) {
        batch.put(key, JSON.stringify(items[key]).toString());
      }

      batch.write(() => {
        callback();
      });
    }
  }
開發者ID:laquereric,項目名稱:wexond,代碼行數:13,代碼來源:storage-area.ts

示例5: remove

  public remove(keys: any, callback: any) {
    if (typeof keys === 'string') {
      this.db.del(keys, err => {
        callback();
      });
    } else if (Array.isArray(keys)) {
      const batch = this.db.batch();

      for (const key of keys) {
        batch.del(key);
      }

      batch.write(() => {
        callback();
      });
    } else {
      // error
    }
  }
開發者ID:laquereric,項目名稱:wexond,代碼行數:19,代碼來源:storage-area.ts

示例6: addKeys

  async addKeys(params) {
    const { name, keys, encryptionKey } = params;
    const ops = keys.map(key => {
      let { pubKey } = key;
      pubKey =
        pubKey || new bitcoreLib.PrivateKey(key.privKey).publicKey.toString();
      let payload = {};
      if (pubKey && key.privKey && encryptionKey) {
        const encKey = Encryption.encryptPrivateKey(
          JSON.stringify(key),
          Buffer.from(pubKey, 'hex'),
          Buffer.from(encryptionKey, 'hex')
        );
        payload = { encKey, pubKey };
      }
      return {
        type: 'put',
        key: `key|${name}|${key.address}`,
        value: JSON.stringify(payload)
      };
    });

    return this.db.batch(ops);
  }
開發者ID:bitjson,項目名稱:bitcore,代碼行數:24,代碼來源:storage.ts


注:本文中的levelup.LevelUp.batch方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。