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

88.89% Statements 16/18
25% Branches 1/4
75% Functions 3/4
88.89% Lines 16/18
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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90  4x 4x 4x 4x 4x 4x                           4x                                             5x 5x 5x 5x                         13x     13x             3x   3x       3x                            
import { Point } from "./geo/point";
import * as Geo from "./geo";
import { CollectionReference } from "./collection";
import { Command } from "./command";
import { ServerDate } from "./serverDate";
import { Request } from "./request";
import { RegExpConstructor } from "./regexp";
 
/**
 * 地理位置类型
 */
interface GeoTeyp {
  Point: typeof Point;
}
 
/**
 * 数据库模块
 *
 * @author haroldhu
 */
export class Db {
  /**
   * Geo 类型
   */
  Geo: GeoTeyp;
 
  /**
   * 逻辑操作的命令
   */
  command: Command;
 
  RegExp: any;
 
  /**
   * 初始化
   *
   * 默认是 `default` 数据库,为今后扩展使用
   *
   * @param config
   */
  config: any;
 
  constructor(config?: any) {
    this.config = config;
    this.Geo = Geo;
    this.command = new Command();
    this.RegExp = RegExpConstructor;
  }
 
  serverDate({ offset = 0 } = {}) {
    return new ServerDate({ offset });
  }
 
  /**
   * 获取集合的引用
   *
   * @param collName - 集合名称
   */
  collection(collName: string): CollectionReference {
    Iif (!collName) {
      throw new Error("Collection name is required");
    }
    return new CollectionReference(this, collName);
  }
 
  /**
   * 创建集合
   */
  createCollection(collName: string) {
    let request = new Request(this);
 
    const params = {
      collectionName: collName
    };
 
    return request.send("addCollection", params);
  }
 
  // /**
  //  * 获取全部集合列表
  //  *
  //  * @internal
  //  * @todo
  //  * @description 后续版本规划
  //  */
  // private getCollections(): void {
 
  // }
}