跳到主要内容

数据库

Class: DB

提供数据库操作的单例类。

静态方法

getInstance

static getInstance(): DB

获取 DB 的单例实例。

  • 返回: DB 实例

方法

show

show(): Promise<TableList>

列出数据库中的所有表。

  • 返回: Promise<TableList>

describe

describe(table: string): Promise<TableDescription>

获取表的描述信息。

  • 参数:
    • table: 表名
  • 返回: Promise<TableDescription>

select

select(table: string, options?: SelectOptions): Promise<SelectResult>

从表中查询数据。

  • 参数:
    • table: 表名
    • options: 可选的查询选项
  • 返回: Promise<SelectResult>

接口

TableField

interface TableField {
name: string;
type: string;
nullable: boolean;
default?: string | null;
}

TableDescription

interface TableDescription {
table: string;
fields: TableField[];
}

TableList

interface TableList {
tables: string[];
}

SelectOptions

interface SelectOptions {
fields?: string[];
where?: Record<string, any>;
limit?: number;
offset?: number;
orderBy?: string;
order?: 'asc' | 'desc';
}

SelectResult

interface SelectResult {
total: number;
rows: Record<string, any>[];
}