Skip to content

MongoDB 和 Redis 的查询都基于 Typescript。自动完成也基于 Monaco Editor 的 Typescript 功能。

MongoDB

查询示例:

typescript
mongoshell((db) => {
  db.collection("user").find().limit(12).skip(1);
});

TIP

mongoshell(db => {})会在打开编辑器时自动填充,不需要手动输入。

TIP

函数也可以是异步的。

TIP

打包了tsc,所以可以输入Typescript。

可以声明多条命令。命令中也可以定义参数。

typescript
mongoshell((db) => {
  // 声明带有参数的命令
  db.collection("user")
    .find()
    .limit(params.int("limit"))
    .skip(params.int("skip", { default: 1 }));
});

Redis

查询示例:

typescript
redisshell((cli) => {
  // 根据滚动自动加载的扫描命令
  cli.scan(0).stream();

  // 声明带有参数的命令
  cli.get(params.string("key", { default: "hello" }));
});

可以声明多条命令。命令中也可以定义参数。

对于各种 Scan 命令,都有额外的stream()方法,可以根据表格滚动自动获取。

一些命令也有其他扩展参数,例如,下面的命令会扫描所有内存占用>= 56 的 key:

typescript
redisshell((cli) => {
  cli.scan(0, { memory: 56 }).stream();
});

参数说明

参数 Api 由全局变量params提供。具体请参见Params 说明

其他的 JavaScript 接口

typescript
declare class Base64 {
  static encode(input: Uint8Array): string;
  static decode(input: string): Uint8Array;
}

declare function ObjectId(inputId?: string | number | IObjectId): IObjectId;

declare function http(
  method: string,
  url: string,
  opts?: {
    headers?: { [k: string]: string[] };
    timeouts?: number;
    proxy?: string;
    body?: ["file", string] | Uint8Array;
  }
): Promise<{
  code: number;
  message: string;
  headers: { [k: string]: string[] };
  body: Uint8Array;
}>;

interface IObjectId {
  toString(): string;
  toHexString(): string;
}