Toshihiko
    Preparing search index...

    Class Toshihiko<AdapterInstance, Options>

    The database entry point used to define models and execute Adapter-level operations.

    Construct it with an Adapter name, constructor, or instance. The selected Adapter determines the option, connection, and execution-result types carried into Models and Queries.

    Type Parameters

    Hierarchy

    • EventEmitter2
      • Toshihiko
    Index
    cache: Cache | null | undefined

    Cache created from options.cache, when configured.

    dialect: string | null

    Adapter name or constructor name used for this instance.

    options: Options

    Adapter-specific options supplied to the constructor.

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

    MySQL connection pool when exposed by the selected Adapter.

    • get database(): string

      The database name reported by the selected Adapter.

      Returns string

    • Defines a typed Model for one table or collection.

      Field names and values are inferred from the schema array. Functions in options.methods are copied onto the returned Model and receive a contextually typed this containing both the Model API and the other custom methods.

      Type Parameters

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

      Parameters

      Returns Model<Name, Schema, AdapterInstance> & Methods

      A Model extended with the inferred custom methods.

      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();
      },
      },
      });
    • Creates a Cache from an existing Cache instance or module-style options.

      Parameters

      • source: CacheSource

        Cache instance or { module, options } configuration.

      Returns Cache | null

      The existing or newly created Cache, or null when the source is not a recognized Cache configuration.