Class Model<T>

Type Parameters

  • T extends object

    The type of the model, which will be returned when using methods such as First() or All()

Hierarchy

  • Model

Constructors

  • Type Parameters

    Type Parameters

    • T extends object

      The type of the model, which will be returned when using methods such as First() or All()

    Parameters

    • options: { D1Orm: D1Orm; tableName: string }

      The options for the model. The table name & D1Orm instance are required.

      • D1Orm: D1Orm

        The D1Orm instance to use.

      • tableName: string

        The name of the table to use.

    • columns: Record<Extract<keyof T, string>, ModelColumn>

      The columns for the model. The keys are the column names, and the values are the column options. See ModelColumn

    Returns Model<T>

Properties

columns: Record<string, ModelColumn>
tableName: string

Accessors

  • get createTableDefinition(): string
  • Returns

    A CreateTable definition for the model, which can be used in a CREATE TABLE statement.

    Returns string

Methods

  • Throws

    • Throws an error if the table already exists and the strategy is not "force".
    • Throws an error if the strategy is "alter", as this is not yet implemented

    Parameters

    • options: { strategy: "default" | "force" | "alter" } = ...

      The options for creating the table. Currently only contains strategy, which is the strategy to use when creating the table.

      • "default" - The default strategy, which will attempt create the table.
      • "force" - Drops the table if it exists, then creates it
      • "alter" - [NOT YET IMPLEMENTED] Attempts to alter the table to match the model
      • strategy: "default" | "force" | "alter"

    Returns Promise<D1Result<unknown>>

  • Parameters

    • Optional silent: boolean

      If true, will ignore the table not existing. If false, will throw an error if the table does not exist.

    Returns Promise<D1Result<unknown>>

  • Upserting is a way to insert a row into the table, or update it if it already exists. This is done by using SQLITE's ON CONFLICT clause. As a result, this method should control the primary key for the insert & where clauses, and should not be used with auto incrementing keys.

    Parameters

    Returns Promise<D1Result<unknown>>

Generated using TypeDoc