# Class BaseSQLiteDatabase<TResultKind, TRunResult, TFullSchema, TSchema>

#### Type Parameters

- TResultKind extends "sync" | "async"
- TRunResult
- TFullSchema extends Record<string, unknown> = Record<string, never>
- TSchema extends TablesRelationalConfig = ExtractTablesWithRelations<TFullSchema>

#### Hierarchy (View Summary)

- BaseSQLiteDatabase
  - SQLiteTransaction

- Defined in node_modules/.pnpm/drizzle-orm@0.44.6_@cloudflare+workers-types@4.20251014.0_@opentelemetry+api@1.9.0_@typ_31a6f5ca8f102af87864dd251ed08d88/node_modules/drizzle-orm/sqlite-core/db.d.ts:16

##### Index

### Constructors

constructor

### Properties

_
$cache
$with
query
[entityKind]

### Methods

$count
all
delete
get
insert
run
select
selectDistinct
transaction
update
values
with

## Constructors

### constructor

- new BaseSQLiteDatabase<
  TResultKind extends "sync"
  | "async",
  TRunResult,
  TFullSchema extends Record<string, unknown> = Record<string, never>,
  TSchema extends
  TablesRelationalConfig = ExtractTablesWithRelations<TFullSchema>,
  >(
  resultKind: TResultKind,
  schema: RelationalSchemaConfig<TSchema> | undefined,
  ): BaseSQLiteDatabase<TResultKind, TRunResult, TFullSchema, TSchema>

  #### Type Parameters

  - TResultKind extends "sync" | "async"
  - TRunResult
  - TFullSchema extends Record<string, unknown> = Record<string, never>
  - TSchema extends TablesRelationalConfig = ExtractTablesWithRelations<TFullSchema>

  #### Parameters

  - resultKind: TResultKind
  - schema: RelationalSchemaConfig<TSchema> | undefined

  #### Returns BaseSQLiteDatabase<TResultKind, TRunResult, TFullSchema, TSchema>

  - Defined in node_modules/.pnpm/drizzle-orm@0.44.6_@cloudflare+workers-types@4.20251014.0_@opentelemetry+api@1.9.0_@typ_31a6f5ca8f102af87864dd251ed08d88/node_modules/drizzle-orm/sqlite-core/db.d.ts:27

## Properties

### `Readonly`_

_: {
fullSchema: TFullSchema;
schema: TSchema | undefined;
tableNamesMap: Record<string, string>;
}

- Defined in node_modules/.pnpm/drizzle-orm@0.44.6_@cloudflare+workers-types@4.20251014.0_@opentelemetry+api@1.9.0_@typ_31a6f5ca8f102af87864dd251ed08d88/node_modules/drizzle-orm/sqlite-core/db.d.ts:19

### $cache

$cache: { invalidate: (params: MutationOption) => Promise<void> }

#### Type Declaration

- ##### invalidate: (params: MutationOption) => Promise<void>

- Defined in node_modules/.pnpm/drizzle-orm@0.44.6_@cloudflare+workers-types@4.20251014.0_@opentelemetry+api@1.9.0_@typ_31a6f5ca8f102af87864dd251ed08d88/node_modules/drizzle-orm/sqlite-core/db.d.ts:194

### $with

$with: WithBuilder

Creates a subquery that defines a temporary named result set as a CTE.

It is useful for breaking down complex queries into simpler parts and for reusing the result set in subsequent parts of the query.

See docs: https://orm.drizzle.team/docs/select#with-clause

#### Param: alias

The alias for the subquery.

Failure to provide an alias will result in a DrizzleTypeError, preventing the subquery from being referenced in other queries.

#### Example

    // Create a subquery with alias 'sq' and use it in the select query
    const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));

    const result = await db.with(sq).select().from(sq);

To select arbitrary SQL values as fields in a CTE and reference them in other CTEs or in the main query, you need to add aliases to them:

    // Select an arbitrary SQL value as a field in a CTE and reference it in the main query
    const sq = db.$with('sq').as(db.select({
      name: sql<string>`upper(${users.name})`.as('name'),
    })
    .from(users));

    const result = await db.with(sq).select({ name: sq.name }).from(sq);

- Defined in node_modules/.pnpm/drizzle-orm@0.44.6_@cloudflare+workers-types@4.20251014.0_@opentelemetry+api@1.9.0_@typ_31a6f5ca8f102af87864dd251ed08d88/node_modules/drizzle-orm/sqlite-core/db.d.ts:67

### query

query: TFullSchema extends Record<string, never>
? DrizzleTypeError<
"Seems like the schema generic is missing - did you forget to add it to your DB type?",
>
: {
[K in string
| number
| symbol]: RelationalQueryBuilder<
TResultKind,
TFullSchema,
TSchema,
TSchema[K],
>
}

- Defined in node_modules/.pnpm/drizzle-orm@0.44.6_@cloudflare+workers-types@4.20251014.0_@opentelemetry+api@1.9.0_@typ_31a6f5ca8f102af87864dd251ed08d88/node_modules/drizzle-orm/sqlite-core/db.d.ts:24

### `Static` `Readonly`[entityKind]

"[entityKind]": string

- Defined in node_modules/.pnpm/drizzle-orm@0.44.6_@cloudflare+workers-types@4.20251014.0_@opentelemetry+api@1.9.0_@typ_31a6f5ca8f102af87864dd251ed08d88/node_modules/drizzle-orm/sqlite-core/db.d.ts:18

## Methods

### $count

- $count(
  source:
  | SQLWrapper
  | SQLiteTable<TableConfig>
  | SQLiteViewBase<string, boolean, ColumnsSelection>
  | SQL<unknown>,
  filters?: SQL<unknown>,
  ): SQLiteCountBuilder<
  SQLiteSession<TResultKind, TRunResult, TFullSchema, TSchema>,
  >

  #### Parameters

  - source:
    | SQLWrapper
    | SQLiteTable<TableConfig>
    | SQLiteViewBase<string, boolean, ColumnsSelection>
    | SQL<unknown>
  - `Optional` filters: SQL<unknown>

  #### Returns SQLiteCountBuilder<SQLiteSession<TResultKind, TRunResult, TFullSchema, TSchema>>

  - Defined in node_modules/.pnpm/drizzle-orm@0.44.6_@cloudflare+workers-types@4.20251014.0_@opentelemetry+api@1.9.0_@typ_31a6f5ca8f102af87864dd251ed08d88/node_modules/drizzle-orm/sqlite-core/db.d.ts:68

### all

- all<T = unknown>(query: string | SQLWrapper): DBResult<TResultKind, T[]>

  #### Type Parameters

  - T = unknown

  #### Parameters

  - query: string | SQLWrapper

  #### Returns DBResult<TResultKind, T[]>

  - Defined in node_modules/.pnpm/drizzle-orm@0.44.6_@cloudflare+workers-types@4.20251014.0_@opentelemetry+api@1.9.0_@typ_31a6f5ca8f102af87864dd251ed08d88/node_modules/drizzle-orm/sqlite-core/db.d.ts:248

### delete

- delete<TTable extends SQLiteTable<TableConfig>>(
  from: TTable,
  ): SQLiteDeleteBase<TTable, TResultKind, TRunResult>

  Creates a delete query.

  Calling this method without `.where()` clause will delete all rows in a table. The `.where()` clause specifies which rows should be deleted.

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

  #### Type Parameters

  - TTable extends SQLiteTable<TableConfig>

  #### Parameters

  - from: TTable

  #### Returns SQLiteDeleteBase<TTable, TResultKind, TRunResult>

  #### Example

      // Delete all rows in the 'cars' table
      await db.delete(cars);

      // Delete rows with filters and conditions
      await db.delete(cars).where(eq(cars.color, 'green'));

      // Delete with returning clause
      const deletedCar: Car[] = await db.delete(cars)
        .where(eq(cars.id, 1))
        .returning();

  - Defined in node_modules/.pnpm/drizzle-orm@0.44.6_@cloudflare+workers-types@4.20251014.0_@opentelemetry+api@1.9.0_@typ_31a6f5ca8f102af87864dd251ed08d88/node_modules/drizzle-orm/sqlite-core/db.d.ts:246

### get

- get<T = unknown>(query: string | SQLWrapper): DBResult<TResultKind, T>

  #### Type Parameters

  - T = unknown

  #### Parameters

  - query: string | SQLWrapper

  #### Returns DBResult<TResultKind, T>

  - Defined in node_modules/.pnpm/drizzle-orm@0.44.6_@cloudflare+workers-types@4.20251014.0_@opentelemetry+api@1.9.0_@typ_31a6f5ca8f102af87864dd251ed08d88/node_modules/drizzle-orm/sqlite-core/db.d.ts:249

### insert

- insert<TTable extends SQLiteTable<TableConfig>>(
  into: TTable,
  ): SQLiteInsertBuilder<TTable, TResultKind, TRunResult>

  Creates an insert query.

  Calling this method will create new rows in a table. Use `.values()` method to specify which values to insert.

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

  #### Type Parameters

  - TTable extends SQLiteTable<TableConfig>

  #### Parameters

  - into: TTable

  #### Returns SQLiteInsertBuilder<TTable, TResultKind, TRunResult>

  #### Example

      // Insert one row
      await db.insert(cars).values({ brand: 'BMW' });

      // Insert multiple rows
      await db.insert(cars).values([{ brand: 'BMW' }, { brand: 'Porsche' }]);

      // Insert with returning clause
      const insertedCar: Car[] = await db.insert(cars)
        .values({ brand: 'BMW' })
        .returning();

  - Defined in node_modules/.pnpm/drizzle-orm@0.44.6_@cloudflare+workers-types@4.20251014.0_@opentelemetry+api@1.9.0_@typ_31a6f5ca8f102af87864dd251ed08d88/node_modules/drizzle-orm/sqlite-core/db.d.ts:221

### run

- run(query: string | SQLWrapper): DBResult<TResultKind, TRunResult>

  #### Parameters

  - query: string | SQLWrapper

  #### Returns DBResult<TResultKind, TRunResult>

  - Defined in node_modules/.pnpm/drizzle-orm@0.44.6_@cloudflare+workers-types@4.20251014.0_@opentelemetry+api@1.9.0_@typ_31a6f5ca8f102af87864dd251ed08d88/node_modules/drizzle-orm/sqlite-core/db.d.ts:247

### select

- select(): SQLiteSelectBuilder<undefined, TResultKind, TRunResult>

  Creates a select query.

  Calling this method with no arguments will select all columns from the table. Pass a selection object to specify the columns you want to select.

  Use `.from()` method to specify which table to select from.

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

  #### Returns SQLiteSelectBuilder<undefined, TResultKind, TRunResult>

  #### Example

      // Select all columns and all rows from the 'cars' table
      const allCars: Car[] = await db.select().from(cars);

      // Select specific columns and all rows from the 'cars' table
      const carsIdsAndBrands: { id: number; brand: string }[] = await db.select({
        id: cars.id,
        brand: cars.brand
      })
        .from(cars);

  Like in SQL, you can use arbitrary expressions as selection fields, not just table columns:

      // Select specific columns along with expression and all rows from the 'cars' table
      const carsIdsAndLowerNames: { id: number; lowerBrand: string }[] = await db.select({
        id: cars.id,
        lowerBrand: sql<string>`lower(${cars.brand})`,
      })
        .from(cars);

  - Defined in node_modules/.pnpm/drizzle-orm@0.44.6_@cloudflare+workers-types@4.20251014.0_@opentelemetry+api@1.9.0_@typ_31a6f5ca8f102af87864dd251ed08d88/node_modules/drizzle-orm/sqlite-core/db.d.ts:137
- select<TSelection extends SelectedFields>(
  fields: TSelection,
  ): SQLiteSelectBuilder<TSelection, TResultKind, TRunResult>

  Creates a select query.

  Calling this method with no arguments will select all columns from the table. Pass a selection object to specify the columns you want to select.

  Use `.from()` method to specify which table to select from.

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

  #### Type Parameters

  - TSelection extends SelectedFields

  #### Parameters

  - fields: TSelection

    The selection object.

  #### Returns SQLiteSelectBuilder<TSelection, TResultKind, TRunResult>

  #### Example

      // Select all columns and all rows from the 'cars' table
      const allCars: Car[] = await db.select().from(cars);

      // Select specific columns and all rows from the 'cars' table
      const carsIdsAndBrands: { id: number; brand: string }[] = await db.select({
        id: cars.id,
        brand: cars.brand
      })
        .from(cars);

  Like in SQL, you can use arbitrary expressions as selection fields, not just table columns:

      // Select specific columns along with expression and all rows from the 'cars' table
      const carsIdsAndLowerNames: { id: number; lowerBrand: string }[] = await db.select({
        id: cars.id,
        lowerBrand: sql<string>`lower(${cars.brand})`,
      })
        .from(cars);

  - Defined in node_modules/.pnpm/drizzle-orm@0.44.6_@cloudflare+workers-types@4.20251014.0_@opentelemetry+api@1.9.0_@typ_31a6f5ca8f102af87864dd251ed08d88/node_modules/drizzle-orm/sqlite-core/db.d.ts:138

### selectDistinct

- selectDistinct(): SQLiteSelectBuilder<undefined, TResultKind, TRunResult>

  Adds `distinct` expression to the select query.

  Calling this method will return only unique values. When multiple columns are selected, it returns rows with unique combinations of values in these columns.

  Use `.from()` method to specify which table to select from.

  See docs: https://orm.drizzle.team/docs/select#distinct

  #### Returns SQLiteSelectBuilder<undefined, TResultKind, TRunResult>

  #### Example

      // Select all unique rows from the 'cars' table
      await db.selectDistinct()
        .from(cars)
        .orderBy(cars.id, cars.brand, cars.color);

      // Select all unique brands from the 'cars' table
      await db.selectDistinct({ brand: cars.brand })
        .from(cars)
        .orderBy(cars.brand);

  - Defined in node_modules/.pnpm/drizzle-orm@0.44.6_@cloudflare+workers-types@4.20251014.0_@opentelemetry+api@1.9.0_@typ_31a6f5ca8f102af87864dd251ed08d88/node_modules/drizzle-orm/sqlite-core/db.d.ts:164
- selectDistinct<TSelection extends SelectedFields>(
  fields: TSelection,
  ): SQLiteSelectBuilder<TSelection, TResultKind, TRunResult>

  Adds `distinct` expression to the select query.

  Calling this method will return only unique values. When multiple columns are selected, it returns rows with unique combinations of values in these columns.

  Use `.from()` method to specify which table to select from.

  See docs: https://orm.drizzle.team/docs/select#distinct

  #### Type Parameters

  - TSelection extends SelectedFields

  #### Parameters

  - fields: TSelection

    The selection object.

  #### Returns SQLiteSelectBuilder<TSelection, TResultKind, TRunResult>

  #### Example

      // Select all unique rows from the 'cars' table
      await db.selectDistinct()
        .from(cars)
        .orderBy(cars.id, cars.brand, cars.color);

      // Select all unique brands from the 'cars' table
      await db.selectDistinct({ brand: cars.brand })
        .from(cars)
        .orderBy(cars.brand);

  - Defined in node_modules/.pnpm/drizzle-orm@0.44.6_@cloudflare+workers-types@4.20251014.0_@opentelemetry+api@1.9.0_@typ_31a6f5ca8f102af87864dd251ed08d88/node_modules/drizzle-orm/sqlite-core/db.d.ts:165

### transaction

- transaction<T>(
  transaction: (
  tx: SQLiteTransaction<TResultKind, TRunResult, TFullSchema, TSchema>,
  ) => Result<TResultKind, T>,
  config?: SQLiteTransactionConfig,
  ): Result<TResultKind, T>

  #### Type Parameters

  - T

  #### Parameters

  - transaction: (
    tx: SQLiteTransaction<TResultKind, TRunResult, TFullSchema, TSchema>,
    ) => Result<TResultKind, T>
  - `Optional` config: SQLiteTransactionConfig

  #### Returns Result<TResultKind, T>

  - Defined in node_modules/.pnpm/drizzle-orm@0.44.6_@cloudflare+workers-types@4.20251014.0_@opentelemetry+api@1.9.0_@typ_31a6f5ca8f102af87864dd251ed08d88/node_modules/drizzle-orm/sqlite-core/db.d.ts:251

### update

- update<TTable extends SQLiteTable<TableConfig>>(
  table: TTable,
  ): SQLiteUpdateBuilder<TTable, TResultKind, TRunResult>

  Creates an update query.

  Calling this method without `.where()` clause will update all rows in a table. The `.where()` clause specifies which rows should be updated.

  Use `.set()` method to specify which values to update.

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

  #### Type Parameters

  - TTable extends SQLiteTable<TableConfig>

  #### Parameters

  - table: TTable

    The table to update.

  #### Returns SQLiteUpdateBuilder<TTable, TResultKind, TRunResult>

  #### Example

      // Update all rows in the 'cars' table
      await db.update(cars).set({ color: 'red' });

      // Update rows with filters and conditions
      await db.update(cars).set({ color: 'red' }).where(eq(cars.brand, 'BMW'));

      // Update with returning clause
      const updatedCar: Car[] = await db.update(cars)
        .set({ color: 'red' })
        .where(eq(cars.id, 1))
        .returning();

  - Defined in node_modules/.pnpm/drizzle-orm@0.44.6_@cloudflare+workers-types@4.20251014.0_@opentelemetry+api@1.9.0_@typ_31a6f5ca8f102af87864dd251ed08d88/node_modules/drizzle-orm/sqlite-core/db.d.ts:193

### values

- values<T extends unknown[] = unknown[]>(
  query: string | SQLWrapper,
  ): DBResult<TResultKind, T[]>

  #### Type Parameters

  - T extends unknown[] = unknown[]

  #### Parameters

  - query: string | SQLWrapper

  #### Returns DBResult<TResultKind, T[]>

  - Defined in node_modules/.pnpm/drizzle-orm@0.44.6_@cloudflare+workers-types@4.20251014.0_@opentelemetry+api@1.9.0_@typ_31a6f5ca8f102af87864dd251ed08d88/node_modules/drizzle-orm/sqlite-core/db.d.ts:250

### with

- with(
  ...queries: WithSubquery<string, Record<string, unknown>>[],
  ): {
  delete: <TTable extends SQLiteTable<TableConfig>>(
  from: TTable,
  ) => SQLiteDeleteBase<TTable, TResultKind, TRunResult>;
  insert: <TTable extends SQLiteTable<TableConfig>>(
  into: TTable,
  ) => SQLiteInsertBuilder<TTable, TResultKind, TRunResult>;
  select: {
  (): SQLiteSelectBuilder<undefined, TResultKind, TRunResult>;
  <TSelection extends SelectedFields>(
  fields: TSelection,
  ): SQLiteSelectBuilder<TSelection, TResultKind, TRunResult>;
  };
  selectDistinct: {
  (): SQLiteSelectBuilder<undefined, TResultKind, TRunResult>;
  <TSelection extends SelectedFields>(
  fields: TSelection,
  ): SQLiteSelectBuilder<TSelection, TResultKind, TRunResult>;
  };
  update: <TTable extends SQLiteTable<TableConfig>>(
  table: TTable,
  ) => SQLiteUpdateBuilder<TTable, TResultKind, TRunResult>;
  }

  Incorporates a previously defined CTE (using `$with`) into the main query.

  This method allows the main query to reference a temporary named result set.

  See docs: https://orm.drizzle.team/docs/select#with-clause

  #### Parameters

  - ...queries: WithSubquery<string, Record<string, unknown>>[]

    The CTEs to incorporate into the main query.

  #### Returns {
  delete: <TTable extends SQLiteTable<TableConfig>>(
  from: TTable,
  ) => SQLiteDeleteBase<TTable, TResultKind, TRunResult>;
  insert: <TTable extends SQLiteTable<TableConfig>>(
  into: TTable,
  ) => SQLiteInsertBuilder<TTable, TResultKind, TRunResult>;
  select: {
  (): SQLiteSelectBuilder<undefined, TResultKind, TRunResult>;
  <TSelection extends SelectedFields>(
  fields: TSelection,
  ): SQLiteSelectBuilder<TSelection, TResultKind, TRunResult>;
  };
  selectDistinct: {
  (): SQLiteSelectBuilder<undefined, TResultKind, TRunResult>;
  <TSelection extends SelectedFields>(
  fields: TSelection,
  ): SQLiteSelectBuilder<TSelection, TResultKind, TRunResult>;
  };
  update: <TTable extends SQLiteTable<TableConfig>>(
  table: TTable,
  ) => SQLiteUpdateBuilder<TTable, TResultKind, TRunResult>;
  }

  #### Example

      // Define a subquery 'sq' as a CTE using $with
      const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));

      // Incorporate the CTE 'sq' into the main query and select from it
      const result = await db.with(sq).select().from(sq);

  - Defined in node_modules/.pnpm/drizzle-orm@0.44.6_@cloudflare+workers-types@4.20251014.0_@opentelemetry+api@1.9.0_@typ_31a6f5ca8f102af87864dd251ed08d88/node_modules/drizzle-orm/sqlite-core/db.d.ts:88