Toshihiko
    正在准备搜索索引...

    类 Toshihiko<AdapterInstance, Options>

    用于定义 Model 和执行 Adapter 层操作的数据库入口。

    可以使用 Adapter 名称、构造函数或实例来构造。所选 Adapter 决定传入 Model 和 Query 的选项、连接及执行结果类型。

    类型参数

    层级

    • EventEmitter2
      • Toshihiko
    索引
    cache: Cache | null | undefined

    由以下配置创建的 Cache:options.cache(如果已配置)。

    dialect: string | null

    此实例使用的 Adapter 名称或构造函数名。

    options: Options

    传给构造函数的 Adapter 特有选项。

    pool: AdapterInstance extends { mysql: Pool } ? Pool : undefined

    所选 Adapter 公开的 MySQL 连接池。

    • get database(): string

      所选 Adapter 报告的数据库名。

      返回 string

    • 为一张表或一个集合定义带类型的 Model。

      字段名和值从 schema 数组推断。以下位置中的函数: options.methods 会被复制到返回的 Model 上,并获得具有上下文类型的 this,其中同时包含 Model API 和其他自定义方法。

      类型参数

      • const Name extends string
      • const Schema extends SchemaDefinition
      • const Methods extends object = object

      参数

      返回 Model<Name, Schema, AdapterInstance> & Methods

      带有推断后自定义方法的 Model。

      const User = database.define('users', [
      { name: 'id', type: Type.Integer, primaryKey: true },
      { name: 'email', type: Type.String },
      ], {
      methods: {
      findByEmail(email: string) {
      return this.where({ email }).findOne();
      },
      },
      });
    • 从现有 Cache 实例或模块式选项创建 Cache。

      参数

      • source: CacheSource

        Cache 实例或 { module, options } 配置。

      返回 Cache | null

      现有或新建的 Cache,或 null,表示 source 不是可识别的 Cache 配置。