All files / tcb-admin-node/src/database collection.ts

100% Statements 8/8
100% Branches 0/0
100% Functions 4/4
100% Lines 8/8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50  4x 4x             4x                     13x             2x                 9x                 1x 1x      
import { Db } from "./db";
import { DocumentReference } from "./document";
import { Query } from "./query";
 
/**
 * 集合模块,继承 Query 模块
 *
 * @author haroldhu
 */
export class CollectionReference extends Query {
 
  /**
   * 初始化
   *
   * @internal
   *
   * @param db    - 数据库的引用
   * @param coll  - 集合名称
   */
  constructor(db: Db, coll: string) {
    super(db, coll);
  }
 
  /**
   * 读取集合名字
   */
  get name() {
    return this._coll;
  }
 
  /**
   * 获取文档的引用
   *
   * @param docID - 文档ID
   */
  doc(docID?: string): DocumentReference {
    return new DocumentReference(this._db, this._coll, docID);
  }
 
  /**
   * 添加一篇文档
   *
   * @param data - 数据
   */
  add(data: Object): Promise<any> {
    let docRef = this.doc();
    return docRef.create(data);
  }
}