Documentation
    Preparing search index...

    Class SQLiteInsertBase<TTable, TResultType, TRunResult, TReturning, TDynamic, TExcludedMethods>

    Type Parameters

    • TTable extends SQLiteTable
    • TResultType extends "sync" | "async"
    • TRunResult
    • TReturning = undefined
    • TDynamic extends boolean = false
    • TExcludedMethods extends string = never

    Hierarchy

    Implements

    Index

    Constructors

    Properties

    _: {
        dialect: "sqlite";
        dynamic: TDynamic;
        excludedMethods: TExcludedMethods;
        result: TReturning extends undefined ? TRunResult : TReturning[];
        resultType: TResultType;
        returning: TReturning;
        runResult: TRunResult;
        table: TTable;
    }
    "[toStringTag]": string
    all: (
        placeholderValues?: Record<string, unknown>,
    ) => Result<
        TResultType,
        TReturning extends undefined
            ? DrizzleTypeError<".all() cannot be used without .returning()">
            : TReturning[],
    >
    get: (
        placeholderValues?: Record<string, unknown>,
    ) => Result<
        TResultType,
        TReturning extends undefined
            ? DrizzleTypeError<".get() cannot be used without .returning()">
            : TReturning,
    >
    run: (
        placeholderValues?: Record<string, unknown>,
    ) => Result<TResultType, TRunResult>
    values: (
        placeholderValues?: Record<string, unknown>,
    ) => Result<
        TResultType,
        TReturning extends undefined
            ? DrizzleTypeError<".values() cannot be used without .returning()">
            : any[][],
    >
    "[entityKind]": string

    Methods

    • Attaches a callback for only the rejection of the Promise.

      Type Parameters

      • TResult = never

      Parameters

      • OptionalonRejected: ((reason: any) => TResult | PromiseLike<TResult>) | null

      Returns Promise<(TReturning extends undefined ? TRunResult : TReturning[]) | TResult>

      A Promise for the completion of the callback.

    • Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The resolved value cannot be modified from the callback.

      Parameters

      • OptionalonFinally: (() => void) | null

      Returns Promise<TReturning extends undefined ? TRunResult : TReturning[]>

      A Promise for the completion of the callback.

    • Returns SQL

    • Adds an on conflict do nothing clause to the query.

      Calling this method simply avoids inserting a row as its alternative action.

      See docs: https://orm.drizzle.team/docs/insert#on-conflict-do-nothing

      Parameters

      Returns this

      // Insert one row and cancel the insert if there's a conflict
      await db.insert(cars)
      .values({ id: 1, brand: 'BMW' })
      .onConflictDoNothing();

      // Explicitly specify conflict target
      await db.insert(cars)
      .values({ id: 1, brand: 'BMW' })
      .onConflictDoNothing({ target: cars.id });
    • Adds an on conflict do update clause to the query.

      Calling this method will update the existing row that conflicts with the row proposed for insertion as its alternative action.

      See docs: https://orm.drizzle.team/docs/insert#upserts-and-conflicts

      Parameters

      Returns this

      // Update the row if there's a conflict
      await db.insert(cars)
      .values({ id: 1, brand: 'BMW' })
      .onConflictDoUpdate({
      target: cars.id,
      set: { brand: 'Porsche' }
      });

      // Upsert with 'where' clause
      await db.insert(cars)
      .values({ id: 1, brand: 'BMW' })
      .onConflictDoUpdate({
      target: cars.id,
      set: { brand: 'newBMW' },
      where: sql`${cars.createdAt} > '2023-01-01'::date`,
      });
    • Adds a returning clause to the query.

      Calling this method will return the specified fields of the inserted rows. If no fields are specified, all fields will be returned.

      See docs: https://orm.drizzle.team/docs/insert#insert-returning

      Returns SQLiteInsertWithout<
          SQLiteInsertBase<
              TTable,
              TResultType,
              TRunResult,
              TTable["$inferSelect"],
              TDynamic,
              TExcludedMethods,
          >,
          TDynamic,
      >

      // Insert one row and return all fields
      const insertedCar: Car[] = await db.insert(cars)
      .values({ brand: 'BMW' })
      .returning();

      // Insert one row and return only the id
      const insertedCarId: { id: number }[] = await db.insert(cars)
      .values({ brand: 'BMW' })
      .returning({ id: cars.id });
    • Adds a returning clause to the query.

      Calling this method will return the specified fields of the inserted rows. If no fields are specified, all fields will be returned.

      See docs: https://orm.drizzle.team/docs/insert#insert-returning

      Type Parameters

      Parameters

      Returns SQLiteInsertWithout<
          SQLiteInsertBase<
              TTable,
              TResultType,
              TRunResult,
              {
                  [K in string
                  | number
                  | symbol]: {
                      [Key in string | number | symbol]: SelectResultField<
                          TSelectedFields[Key],
                          true,
                      >
                  }[K]
              },
              TDynamic,
              TExcludedMethods,
          >,
          TDynamic,
          "returning",
      >

      // Insert one row and return all fields
      const insertedCar: Car[] = await db.insert(cars)
      .values({ brand: 'BMW' })
      .returning();

      // Insert one row and return only the id
      const insertedCarId: { id: number }[] = await db.insert(cars)
      .values({ brand: 'BMW' })
      .returning({ id: cars.id });
    • Returns boolean

    • Attaches callbacks for the resolution and/or rejection of the Promise.

      Type Parameters

      Parameters

      Returns Promise<TResult1 | TResult2>

      A Promise for the completion of which ever callback is executed.

    • Returns Query