Documentation
    Preparing search index...

    Class SQLiteUpdateBase<TTable, TResultType, TRunResult, TFrom, TReturning, TDynamic, TExcludedMethods>

    Type Parameters

    • TTable extends SQLiteTable = SQLiteTable
    • TResultType extends "sync" | "async" = "sync" | "async"
    • TRunResult = unknown
    • TFrom extends SQLiteTable | Subquery | SQLiteViewBase | SQL | undefined = undefined
    • TReturning = undefined
    • TDynamic extends boolean = false
    • TExcludedMethods extends string = never

    Hierarchy

    Implements

    Index

    Constructors

    Properties

    _: {
        dialect: "sqlite";
        dynamic: TDynamic;
        excludedMethods: TExcludedMethods;
        from: TFrom;
        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[],
    >
    fullJoin: SQLiteUpdateJoinFn<
        SQLiteUpdateBase<
            TTable,
            TResultType,
            TRunResult,
            TFrom,
            TReturning,
            TDynamic,
            TExcludedMethods,
        >,
    >
    get: (
        placeholderValues?: Record<string, unknown>,
    ) => Result<
        TResultType,
        TReturning extends undefined
            ? DrizzleTypeError<".get() cannot be used without .returning()">
            : TReturning,
    >
    innerJoin: SQLiteUpdateJoinFn<
        SQLiteUpdateBase<
            TTable,
            TResultType,
            TRunResult,
            TFrom,
            TReturning,
            TDynamic,
            TExcludedMethods,
        >,
    >
    leftJoin: SQLiteUpdateJoinFn<
        SQLiteUpdateBase<
            TTable,
            TResultType,
            TRunResult,
            TFrom,
            TReturning,
            TDynamic,
            TExcludedMethods,
        >,
    >
    rightJoin: SQLiteUpdateJoinFn<
        SQLiteUpdateBase<
            TTable,
            TResultType,
            TRunResult,
            TFrom,
            TReturning,
            TDynamic,
            TExcludedMethods,
        >,
    >
    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 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.

    • Adds a returning clause to the query.

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

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

      Returns SQLiteUpdateWithout<
          SQLiteUpdateBase<
              TTable,
              TResultType,
              TRunResult,
              TFrom,
              TTable["$inferSelect"],
              TDynamic,
              TExcludedMethods,
          >,
          TDynamic,
      >

      // Update all cars with the green color and return all fields
      const updatedCars: Car[] = await db.update(cars)
      .set({ color: 'red' })
      .where(eq(cars.color, 'green'))
      .returning();

      // Update all cars with the green color and return only their id and brand fields
      const updatedCarsIdsAndBrands: { id: number, brand: string }[] = await db.update(cars)
      .set({ color: 'red' })
      .where(eq(cars.color, 'green'))
      .returning({ id: cars.id, brand: cars.brand });
    • Adds a returning clause to the query.

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

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

      Type Parameters

      Parameters

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

      // Update all cars with the green color and return all fields
      const updatedCars: Car[] = await db.update(cars)
      .set({ color: 'red' })
      .where(eq(cars.color, 'green'))
      .returning();

      // Update all cars with the green color and return only their id and brand fields
      const updatedCarsIdsAndBrands: { id: number, brand: string }[] = await db.update(cars)
      .set({ color: 'red' })
      .where(eq(cars.color, 'green'))
      .returning({ id: cars.id, brand: cars.brand });
    • Adds a 'where' clause to the query.

      Calling this method will update only those rows that fulfill a specified condition.

      See docs: https://orm.drizzle.team/docs/update

      Parameters

      • where: SQL<unknown> | undefined

        the 'where' clause.

      Returns SQLiteUpdateWithout<
          SQLiteUpdateBase<
              TTable,
              TResultType,
              TRunResult,
              TFrom,
              TReturning,
              TDynamic,
              TExcludedMethods,
          >,
          TDynamic,
          "where",
      >

      You can use conditional operators and sql function to filter the rows to be updated.

      // Update all cars with green color
      db.update(cars).set({ color: 'red' })
      .where(eq(cars.color, 'green'));
      // or
      db.update(cars).set({ color: 'red' })
      .where(sql`${cars.color} = 'green'`)

      You can logically combine conditional operators with and() and or() operators:

      // Update all BMW cars with a green color
      db.update(cars).set({ color: 'red' })
      .where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));

      // Update all cars with the green or blue color
      db.update(cars).set({ color: 'red' })
      .where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));