Skip to content

@unthrown/drizzle


@unthrown/drizzle / index

index ​

Builders ​

PgUnthrownCountBuilder ​

Defined in: packages/drizzle/src/pg-core/count.ts:37

A $count query that resolves to an AsyncResult.

Remarks ​

The one builder with no _prepare: it inherits from drizzle's PgCountBuilder, which is itself an SQL fragment, so it can be embedded in a larger query as well as run on its own. Running it prepares the count inline.

Extends ​

  • PgCountBuilder

Constructors ​

Constructor ​
ts
new PgUnthrownCountBuilder(__namedParameters): PgUnthrownCountBuilder;

Defined in: packages/drizzle/src/pg-core/count.ts:42

Parameters ​
ParameterType
__namedParameters{ dialect: PgDialect; filters?: SQL<unknown>; session: PgUnthrownSession<unknown>; source: | PgTable<TableConfig> | PgViewBase<ViewConfig<ColumnsSelection>> | SQL<unknown> | SQLWrapper<unknown>; }
__namedParameters.dialectPgDialect
__namedParameters.filters?SQL<unknown>
__namedParameters.sessionPgUnthrownSession<unknown>
__namedParameters.source| PgTable<TableConfig> | PgViewBase<ViewConfig<ColumnsSelection>> | SQL<unknown> | SQLWrapper<unknown>
Returns ​

PgUnthrownCountBuilder

Overrides ​

PgCountBuilder.constructor

Properties ​

PropertyModifierTypeDefault valueDescriptionOverridesInherited fromDefined in
_publicobjectundefined--PgCountBuilder._node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/sql/sql.d.ts:60
_.brandpublic"SQL"undefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/sql/sql.d.ts:61
_.typepublicnumberundefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/sql/sql.d.ts:62
queryChunksreadonlySQLChunk[]undefined--PgCountBuilder.queryChunksnode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/sql/sql.d.ts:58
thenreadonlyResultThen<number, never>...The then that makes a query builder awaitable, resolving to a Result. Remarks Drizzle's promise and Effect trees each make their builders runnable the same way: the builder carries a then that defers to execute(). The promise tree gets it from the QueryPromise mixin, whose then is literally this.execute().then(onFulfilled, onRejected). This package cannot reuse that mixin. QueryPromise<T> declares execute(): Promise<T>, and ours returns an AsyncResult<T, PgQueryError> — so merging its type would contradict the very method it delegates to. (Its applyMixins helper is @internal and absent from drizzle's published .d.ts besides.) Each builder therefore declares this then itself, built by resultThen, with the awaited type it actually produces. Awaiting a builder yields a Result, never a rejection: execute() returns an AsyncResult, whose internal promise never rejects, and the compilation step ahead of it runs inside the same boundary — see runQuery. catch and finally are deliberately not offered: there is no rejection for them to observe. onRejected is still forwarded, exactly as AsyncResult.then forwards it, so a hypothetical internal rejection settles the await instead of hanging it.--packages/drizzle/src/pg-core/count.ts:83
[entityKind]static readonlystring"PgUnthrownCountBuilder"-PgCountBuilder.[entityKind]-packages/drizzle/src/pg-core/count.ts:38

Methods ​

append() ​
ts
append(query): this;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/sql/sql.d.ts:65

Parameters ​
ParameterType
querySQL
Returns ​

this

Inherited from ​

PgCountBuilder.append

as() ​
Call Signature ​
ts
as(alias): Aliased<number>;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/sql/sql.d.ts:71

Parameters ​
ParameterType
aliasstring
Returns ​

Aliased<number>

Inherited from ​

PgCountBuilder.as

Call Signature ​
ts
as<TData>(): SQL<TData>;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/sql/sql.d.ts:76

Type Parameters ​
Type Parameter
TData
Returns ​

SQL<TData>

Deprecated ​

Use sql\<DataType\>`query`.as(alias) instead.

Inherited from ​

PgCountBuilder.as

Call Signature ​
ts
as<TData>(alias): Aliased<TData>;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/sql/sql.d.ts:81

Type Parameters ​
Type Parameter
TData
Parameters ​
ParameterType
aliasstring
Returns ​

Aliased<TData>

Deprecated ​

Use sql\<DataType\>`query`.as(alias) instead.

Inherited from ​

PgCountBuilder.as

buildQueryFromSourceParams() ​
ts
buildQueryFromSourceParams(chunks, _config): Query;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/sql/sql.d.ts:67

Parameters ​
ParameterType
chunksSQLChunk[]
_configBuildQueryConfig
Returns ​

Query

Inherited from ​

PgCountBuilder.buildQueryFromSourceParams

execute() ​
ts
execute(placeholderValues?): AsyncResult<number, never>;

Defined in: packages/drizzle/src/pg-core/count.ts:66

Run the count, resolving to the number of matching rows.

The error channel is never — a count is a read, so every failure it can hit is a defect. See runSafeQuery.

Parameters ​
ParameterType
placeholderValues?Record<string, unknown>
Returns ​

AsyncResult<number, never>

getSQL() ​
ts
getSQL(): SQL<number>;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/sql/sql.d.ts:70

Returns ​

SQL<number>

Inherited from ​

PgCountBuilder.getSQL

if() ​
ts
if(condition): PgUnthrownCountBuilder | undefined;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/sql/sql.d.ts:91

This method is used to conditionally include a part of the query.

Parameters ​
ParameterTypeDescription
conditionanyCondition to check
Returns ​

PgUnthrownCountBuilder | undefined

itself if the condition is true, otherwise undefined

Inherited from ​

PgCountBuilder.if

inlineParams() ​
ts
inlineParams(): this;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/sql/sql.d.ts:84

Returns ​

this

Inherited from ​

PgCountBuilder.inlineParams

mapWith() ​
ts
mapWith<TDecoder>(decoder): SQL<GetDecoderResult<TDecoder>>;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/sql/sql.d.ts:82

Type Parameters ​
Type Parameter
TDecoder extends | DriverValueDecoder<any, number> | DriverValueDecoderFn<any, number>
Parameters ​
ParameterType
decoderTDecoder
Returns ​

SQL<GetDecoderResult<TDecoder>>

Inherited from ​

PgCountBuilder.mapWith

nullable() ​
ts
nullable(): SQL<number | null>;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/sql/sql.d.ts:83

Returns ​

SQL<number | null>

Inherited from ​

PgCountBuilder.nullable

toQuery() ​
ts
toQuery(config): Query;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/sql/sql.d.ts:66

Parameters ​
ParameterType
configBuildQueryConfig
Returns ​

Query

Inherited from ​

PgCountBuilder.toQuery


PgUnthrownDeleteBase ​

Defined in: packages/drizzle/src/pg-core/delete.ts:58

A delete query that resolves to an AsyncResult.

Remarks ​

Deleting a row another table still references raises a ForeignKeyViolation, which lands in the error channel rather than as a rejection.

Extends ​

  • PgDeleteBase<PgUnthrownDeleteHKT, TTable, TQueryResult, TSelectedFields, TReturning, TDynamic, TExcludedMethods>

Type Parameters ​

Type ParameterDefault type
TTable extends PgTable-
TQueryResult extends PgQueryResultHKT-
TSelectedFields extends ColumnsSelection | undefinedundefined
TReturning extends Record<string, unknown> | undefinedundefined
TDynamic extends booleanfalse
TExcludedMethods extends stringnever

Constructors ​

Constructor ​
ts
new PgUnthrownDeleteBase<TTable, TQueryResult, TSelectedFields, TReturning, TDynamic, TExcludedMethods>(
   table, 
   session, 
   dialect, 
   withList?
): PgUnthrownDeleteBase<TTable, TQueryResult, TSelectedFields, TReturning, TDynamic, TExcludedMethods>;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/delete.d.ts:66

Parameters ​
ParameterType
tableTTable
sessionPgSession
dialectPgDialect
withList?Subquery<string, Record<string, unknown>>[]
Returns ​

PgUnthrownDeleteBase<TTable, TQueryResult, TSelectedFields, TReturning, TDynamic, TExcludedMethods>

Inherited from ​

PgDeleteBase<PgUnthrownDeleteHKT, TTable, TQueryResult, TSelectedFields, TReturning, TDynamic, TExcludedMethods>.constructor

Properties ​

PropertyModifierTypeDefault valueDescriptionOverridesInherited fromDefined in
_readonlyobjectundefined--PgDeleteBase._node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/delete.d.ts:49
_.dialectreadonly"pg"undefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/delete.d.ts:50
_.dynamicreadonlyTDynamicundefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/delete.d.ts:56
_.excludedMethodsreadonlyTExcludedMethodsundefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/delete.d.ts:57
_.hktreadonlyPgUnthrownDeleteHKTundefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/delete.d.ts:51
_.queryResultreadonlyTQueryResultundefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/delete.d.ts:53
_.resultreadonlyTReturning extends undefined ? PgQueryResultKind<TQueryResult, never> : TReturning[]undefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/delete.d.ts:58
_.returningreadonlyTReturningundefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/delete.d.ts:55
_.selectedFieldsreadonlyTSelectedFieldsundefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/delete.d.ts:54
_.tablereadonlyTTableundefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/delete.d.ts:52
thenreadonlyResultThen<DeleteResult<TQueryResult, TReturning>>...The then that makes a query builder awaitable, resolving to a Result. Remarks Drizzle's promise and Effect trees each make their builders runnable the same way: the builder carries a then that defers to execute(). The promise tree gets it from the QueryPromise mixin, whose then is literally this.execute().then(onFulfilled, onRejected). This package cannot reuse that mixin. QueryPromise<T> declares execute(): Promise<T>, and ours returns an AsyncResult<T, PgQueryError> — so merging its type would contradict the very method it delegates to. (Its applyMixins helper is @internal and absent from drizzle's published .d.ts besides.) Each builder therefore declares this then itself, built by resultThen, with the awaited type it actually produces. Awaiting a builder yields a Result, never a rejection: execute() returns an AsyncResult, whose internal promise never rejects, and the compilation step ahead of it runs inside the same boundary — see runQuery. catch and finally are deliberately not offered: there is no rejection for them to observe. onRejected is still forwarded, exactly as AsyncResult.then forwards it, so a hypothetical internal rejection settles the await instead of hanging it.--packages/drizzle/src/pg-core/delete.ts:121
[entityKind]static readonlystring"PgUnthrownDelete"-PgDeleteBase.[entityKind]-packages/drizzle/src/pg-core/delete.ts:74

Methods ​

$dynamic() ​
ts
$dynamic(): PgUnthrownDeleteBase<Assume<TTable, PgTable<TableConfig>>>;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/delete.d.ts:125

Returns ​

PgUnthrownDeleteBase<Assume<TTable, PgTable<TableConfig>>>

Inherited from ​

PgDeleteBase.$dynamic

comment() ​
ts
comment(comment): PgDeleteWithout<PgUnthrownDeleteBase<TTable, TQueryResult, TSelectedFields, TReturning, TDynamic, TExcludedMethods>, TDynamic, "comment">;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/delete.d.ts:122

Attach sqlcommenter comment to a query

Parameters ​
ParameterType
commentCommentInput
Returns ​

PgDeleteWithout<PgUnthrownDeleteBase<TTable, TQueryResult, TSelectedFields, TReturning, TDynamic, TExcludedMethods>, TDynamic, "comment">

Inherited from ​

PgDeleteBase.comment

execute() ​
ts
execute(placeholderValues?): AsyncResult<DeleteResult<TQueryResult, TReturning>, PgQueryError>;

Defined in: packages/drizzle/src/pg-core/delete.ts:113

Run the delete, resolving to its result or a PgQueryError.

Parameters ​
ParameterType
placeholderValues?Record<string, unknown>
Returns ​

AsyncResult<DeleteResult<TQueryResult, TReturning>, PgQueryError>

getSQL() ​
ts
getSQL(): SQL;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/delete.d.ts:123

Returns ​

SQL

Inherited from ​

PgDeleteBase.getSQL

prepare() ​
ts
prepare(name): PgUnthrownPreparedQuery<PreparedQueryConfig & object>;

Defined in: packages/drizzle/src/pg-core/delete.ts:104

Create a prepared statement for this query. This allows the database to remember this query for the given session and call it by name, rather than specifying the full query.

Postgres prepare documentation

Parameters ​
ParameterType
namestring
Returns ​

PgUnthrownPreparedQuery<PreparedQueryConfig & object>

returning() ​
Call Signature ​
ts
returning(): PgDeleteWithout<PgDeleteKind<PgUnthrownDeleteHKT, TTable, TQueryResult, TTable["_"]["columns"], TTable["$inferSelect"], TDynamic, TExcludedMethods>, TDynamic>;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/delete.d.ts:117

Adds a returning clause to the query.

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

See docs: https://orm.drizzle.team/docs/delete#delete-with-return

Returns ​

PgDeleteWithout<PgDeleteKind<PgUnthrownDeleteHKT, TTable, TQueryResult, TTable["_"]["columns"], TTable["$inferSelect"], TDynamic, TExcludedMethods>, TDynamic>

Example ​
ts
// Delete all cars with the green color and return all fields
const deletedCars: Car[] = await db.delete(cars)
  .where(eq(cars.color, 'green'))
  .returning();

// Delete all cars with the green color and return only their id and brand fields
const deletedCarsIdsAndBrands: { id: number, brand: string }[] = await db.delete(cars)
  .where(eq(cars.color, 'green'))
  .returning({ id: cars.id, brand: cars.brand });
Inherited from ​

PgDeleteBase.returning

Call Signature ​
ts
returning<TSelectedFields>(fields): PgDeleteWithout<PgDeleteKind<PgUnthrownDeleteHKT, TTable, TQueryResult, TSelectedFields, { [K in string | number | symbol]: { [Key in string | number | symbol]: SelectResultField<TSelectedFields[Key], true> }[K] }, TDynamic, TExcludedMethods>, TDynamic, "returning">;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/delete.d.ts:118

Adds a returning clause to the query.

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

See docs: https://orm.drizzle.team/docs/delete#delete-with-return

Type Parameters ​
Type Parameter
TSelectedFields extends SelectedFieldsFlat
Parameters ​
ParameterType
fieldsTSelectedFields
Returns ​

PgDeleteWithout<PgDeleteKind<PgUnthrownDeleteHKT, TTable, TQueryResult, TSelectedFields, { [K in string | number | symbol]: { [Key in string | number | symbol]: SelectResultField<TSelectedFields[Key], true> }[K] }, TDynamic, TExcludedMethods>, TDynamic, "returning">

Example ​
ts
// Delete all cars with the green color and return all fields
const deletedCars: Car[] = await db.delete(cars)
  .where(eq(cars.color, 'green'))
  .returning();

// Delete all cars with the green color and return only their id and brand fields
const deletedCarsIdsAndBrands: { id: number, brand: string }[] = await db.delete(cars)
  .where(eq(cars.color, 'green'))
  .returning({ id: cars.id, brand: cars.brand });
Inherited from ​

PgDeleteBase.returning

shouldOmitSQLParens()? ​
ts
shouldOmitSQLParens?(): boolean;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/sql/sql.d.ts:48

Returns ​

boolean

Inherited from ​

PgDeleteBase.shouldOmitSQLParens

toSQL() ​
ts
toSQL(): Query;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/delete.d.ts:124

Returns ​

Query

Inherited from ​

PgDeleteBase.toSQL

where() ​
ts
where(where): PgDeleteWithout<PgUnthrownDeleteBase<TTable, TQueryResult, TSelectedFields, TReturning, TDynamic, TExcludedMethods>, TDynamic, "where">;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/delete.d.ts:96

Adds a where clause to the query.

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

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

Parameters ​
ParameterTypeDescription
whereSQL<unknown> | undefinedthe where clause.
Returns ​

PgDeleteWithout<PgUnthrownDeleteBase<TTable, TQueryResult, TSelectedFields, TReturning, TDynamic, TExcludedMethods>, TDynamic, "where">

Example ​

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

ts
// Delete all cars with green color
await db.delete(cars).where(eq(cars.color, 'green'));
// or
await db.delete(cars).where(sql`${cars.color} = 'green'`)

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

ts
// Delete all BMW cars with a green color
await db.delete(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));

// Delete all cars with the green or blue color
await db.delete(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
Inherited from ​

PgDeleteBase.where


PgUnthrownInsertBase ​

Defined in: packages/drizzle/src/pg-core/insert.ts:57

An insert query that resolves to an AsyncResult.

Remarks ​

This is where the package earns its keep: a unique index, a foreign key or a NOT NULL column turns a write into a modeled PgQueryError instead of a rejection, so the caller branches on it exhaustively.

Extends ​

  • PgInsertBase<PgUnthrownInsertHKT, TTable, TQueryResult, TSelectedFields, TReturning, TDynamic, TExcludedMethods>

Type Parameters ​

Type ParameterDefault type
TTable extends PgTable-
TQueryResult extends PgQueryResultHKT-
TSelectedFieldsundefined
TReturningundefined
TDynamic extends booleanfalse
TExcludedMethods extends stringnever

Constructors ​

Constructor ​
ts
new PgUnthrownInsertBase<TTable, TQueryResult, TSelectedFields, TReturning, TDynamic, TExcludedMethods>(
   table, 
   values, 
   session, 
   dialect, 
   withList?, 
   select?, 
   columnList?, 
   overridingSystemValue_?
): PgUnthrownInsertBase<TTable, TQueryResult, TSelectedFields, TReturning, TDynamic, TExcludedMethods>;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/insert.d.ts:118

Parameters ​
ParameterType
tableTTable
values| SQL<unknown> | Record<string, unknown>[] | TypedQueryBuilder<{ }, unknown, unknown>
sessionPgSession
dialectPgDialect
withList?Subquery<string, Record<string, unknown>>[]
select?boolean
columnList?string[]
overridingSystemValue_?boolean
Returns ​

PgUnthrownInsertBase<TTable, TQueryResult, TSelectedFields, TReturning, TDynamic, TExcludedMethods>

Inherited from ​

PgInsertBase<PgUnthrownInsertHKT, TTable, TQueryResult, TSelectedFields, TReturning, TDynamic, TExcludedMethods>.constructor

Properties ​

PropertyModifierTypeDefault valueDescriptionOverridesInherited fromDefined in
_readonlyobjectundefined--PgInsertBase._node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/insert.d.ts:101
_.dialectreadonly"pg"undefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/insert.d.ts:102
_.dynamicreadonlyTDynamicundefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/insert.d.ts:108
_.excludedMethodsreadonlyTExcludedMethodsundefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/insert.d.ts:109
_.hktreadonlyPgUnthrownInsertHKTundefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/insert.d.ts:103
_.queryResultreadonlyTQueryResultundefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/insert.d.ts:105
_.resultreadonlyTReturning extends undefined ? PgQueryResultKind<TQueryResult, never> : TReturning[]undefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/insert.d.ts:110
_.returningreadonlyTReturningundefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/insert.d.ts:107
_.selectedFieldsreadonlyTSelectedFieldsundefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/insert.d.ts:106
_.tablereadonlyTTableundefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/insert.d.ts:104
thenreadonlyResultThen<InsertResult<TQueryResult, TReturning>>...The then that makes a query builder awaitable, resolving to a Result. Remarks Drizzle's promise and Effect trees each make their builders runnable the same way: the builder carries a then that defers to execute(). The promise tree gets it from the QueryPromise mixin, whose then is literally this.execute().then(onFulfilled, onRejected). This package cannot reuse that mixin. QueryPromise<T> declares execute(): Promise<T>, and ours returns an AsyncResult<T, PgQueryError> — so merging its type would contradict the very method it delegates to. (Its applyMixins helper is @internal and absent from drizzle's published .d.ts besides.) Each builder therefore declares this then itself, built by resultThen, with the awaited type it actually produces. Awaiting a builder yields a Result, never a rejection: execute() returns an AsyncResult, whose internal promise never rejects, and the compilation step ahead of it runs inside the same boundary — see runQuery. catch and finally are deliberately not offered: there is no rejection for them to observe. onRejected is still forwarded, exactly as AsyncResult.then forwards it, so a hypothetical internal rejection settles the await instead of hanging it.--packages/drizzle/src/pg-core/insert.ts:120
[entityKind]static readonlystring"PgUnthrownInsert"-PgInsertBase.[entityKind]-packages/drizzle/src/pg-core/insert.ts:73

Methods ​

$dynamic() ​
ts
$dynamic(): PgUnthrownInsertBase<Assume<TTable, PgTable<TableConfig>>>;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/insert.d.ts:203

Returns ​

PgUnthrownInsertBase<Assume<TTable, PgTable<TableConfig>>>

Inherited from ​

PgInsertBase.$dynamic

comment() ​
ts
comment(comment): PgInsertWithout<PgUnthrownInsertBase<TTable, TQueryResult, TSelectedFields, TReturning, TDynamic, TExcludedMethods>, TDynamic, "comment">;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/insert.d.ts:200

Attach sqlcommenter comment to a query

Parameters ​
ParameterType
commentCommentInput
Returns ​

PgInsertWithout<PgUnthrownInsertBase<TTable, TQueryResult, TSelectedFields, TReturning, TDynamic, TExcludedMethods>, TDynamic, "comment">

Inherited from ​

PgInsertBase.comment

execute() ​
ts
execute(placeholderValues?): AsyncResult<InsertResult<TQueryResult, TReturning>, PgQueryError>;

Defined in: packages/drizzle/src/pg-core/insert.ts:112

Run the insert, resolving to its result or a PgQueryError.

Parameters ​
ParameterType
placeholderValues?Record<string, unknown>
Returns ​

AsyncResult<InsertResult<TQueryResult, TReturning>, PgQueryError>

getSQL() ​
ts
getSQL(): SQL;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/insert.d.ts:201

Returns ​

SQL

Inherited from ​

PgInsertBase.getSQL

onConflictDoNothing() ​
ts
onConflictDoNothing(config?): PgInsertWithout<PgUnthrownInsertBase<TTable, TQueryResult, TSelectedFields, TReturning, TDynamic, TExcludedMethods>, TDynamic, "onConflictDoNothing" | "onConflictDoUpdate">;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/insert.d.ts:163

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 ​
ParameterTypeDescription
config?{ target?: IndexColumn | IndexColumn[]; where?: SQL<unknown>; }The target and where clauses.
config.target?IndexColumn | IndexColumn[]-
config.where?SQL<unknown>-
Returns ​

PgInsertWithout<PgUnthrownInsertBase<TTable, TQueryResult, TSelectedFields, TReturning, TDynamic, TExcludedMethods>, TDynamic, "onConflictDoNothing" | "onConflictDoUpdate">

Example ​
ts
// 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 });
Inherited from ​

PgInsertBase.onConflictDoNothing

onConflictDoUpdate() ​
ts
onConflictDoUpdate(config): PgInsertWithout<PgUnthrownInsertBase<TTable, TQueryResult, TSelectedFields, TReturning, TDynamic, TExcludedMethods>, TDynamic, "onConflictDoNothing" | "onConflictDoUpdate">;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/insert.d.ts:196

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 ​
ParameterTypeDescription
configPgInsertOnConflictDoUpdateConfig<PgUnthrownInsertBase<TTable, TQueryResult, TSelectedFields, TReturning, TDynamic, TExcludedMethods>>The target, set and where clauses.
Returns ​

PgInsertWithout<PgUnthrownInsertBase<TTable, TQueryResult, TSelectedFields, TReturning, TDynamic, TExcludedMethods>, TDynamic, "onConflictDoNothing" | "onConflictDoUpdate">

Example ​
ts
// 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' },
    targetWhere: sql`${cars.createdAt} > '2023-01-01'::date`,
  });
Inherited from ​

PgInsertBase.onConflictDoUpdate

prepare() ​
ts
prepare(name): PgUnthrownPreparedQuery<PreparedQueryConfig & object>;

Defined in: packages/drizzle/src/pg-core/insert.ts:103

Create a prepared statement for this query. This allows the database to remember this query for the given session and call it by name, rather than specifying the full query.

Postgres prepare documentation

Parameters ​
ParameterType
namestring
Returns ​

PgUnthrownPreparedQuery<PreparedQueryConfig & object>

returning() ​
Call Signature ​
ts
returning(): PgInsertWithout<PgInsertKind<PgUnthrownInsertHKT, TTable, TQueryResult, TTable["_"]["columns"], TTable["$inferSelect"], TDynamic, TExcludedMethods>, TDynamic>;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/insert.d.ts:139

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 ​

PgInsertWithout<PgInsertKind<PgUnthrownInsertHKT, TTable, TQueryResult, TTable["_"]["columns"], TTable["$inferSelect"], TDynamic, TExcludedMethods>, TDynamic>

Example ​
ts
// 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 });
Inherited from ​

PgInsertBase.returning

Call Signature ​
ts
returning<TSelectedFields>(fields): PgInsertWithout<PgInsertKind<PgUnthrownInsertHKT, TTable, TQueryResult, TSelectedFields, { [K in string | number | symbol]: { [Key in string | number | symbol]: SelectResultField<TSelectedFields[Key], true> }[K] }, TDynamic, TExcludedMethods>, TDynamic, "returning">;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/insert.d.ts:140

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 ​
Type Parameter
TSelectedFields extends SelectedFieldsFlat
Parameters ​
ParameterType
fieldsTSelectedFields
Returns ​

PgInsertWithout<PgInsertKind<PgUnthrownInsertHKT, TTable, TQueryResult, TSelectedFields, { [K in string | number | symbol]: { [Key in string | number | symbol]: SelectResultField<TSelectedFields[Key], true> }[K] }, TDynamic, TExcludedMethods>, TDynamic, "returning">

Example ​
ts
// 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 });
Inherited from ​

PgInsertBase.returning

shouldOmitSQLParens()? ​
ts
shouldOmitSQLParens?(): boolean;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/sql/sql.d.ts:48

Returns ​

boolean

Inherited from ​

PgInsertBase.shouldOmitSQLParens

toSQL() ​
ts
toSQL(): Query;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/insert.d.ts:202

Returns ​

Query

Inherited from ​

PgInsertBase.toSQL


PgUnthrownRaw ​

Defined in: packages/drizzle/src/pg-core/raw.ts:22

A raw db.execute(sql\…`)query that resolves to anAsyncResult`.

Remarks ​

Unlike every other builder, this one is handed an already-prepared query — the database prepared it when building the fragment — so _prepare simply returns it and execute runs it.

Extends ​

  • PgRaw<TResult>

Type Parameters ​

Type ParameterDescription
TResultthe driver's result for the statement.

Constructors ​

Constructor ​
ts
new PgUnthrownRaw<TResult>(
   prepared, 
   sql, 
   query
): PgUnthrownRaw<TResult>;

Defined in: packages/drizzle/src/pg-core/raw.ts:31

Parameters ​
ParameterType
preparedPgUnthrownPreparedQuery<{ execute: TResult; }>
sqlSQL
queryQuery
Returns ​

PgUnthrownRaw<TResult>

Overrides ​

PgRaw<TResult>.constructor

Properties ​

PropertyModifierTypeDefault valueDescriptionOverridesInherited fromDefined in
_readonlyobjectundefined--PgRaw._node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/raw.d.ts:12
_.dialectreadonly"pg"undefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/raw.d.ts:13
_.resultreadonlyTResultundefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/raw.d.ts:14
thenreadonlyResultThen<TResult>...The then that makes a query builder awaitable, resolving to a Result. Remarks Drizzle's promise and Effect trees each make their builders runnable the same way: the builder carries a then that defers to execute(). The promise tree gets it from the QueryPromise mixin, whose then is literally this.execute().then(onFulfilled, onRejected). This package cannot reuse that mixin. QueryPromise<T> declares execute(): Promise<T>, and ours returns an AsyncResult<T, PgQueryError> — so merging its type would contradict the very method it delegates to. (Its applyMixins helper is @internal and absent from drizzle's published .d.ts besides.) Each builder therefore declares this then itself, built by resultThen, with the awaited type it actually produces. Awaiting a builder yields a Result, never a rejection: execute() returns an AsyncResult, whose internal promise never rejects, and the compilation step ahead of it runs inside the same boundary — see runQuery. catch and finally are deliberately not offered: there is no rejection for them to observe. onRejected is still forwarded, exactly as AsyncResult.then forwards it, so a hypothetical internal rejection settles the await instead of hanging it.--packages/drizzle/src/pg-core/raw.ts:46
[entityKind]static readonlystring"PgUnthrownRaw"-PgRaw.[entityKind]-packages/drizzle/src/pg-core/raw.ts:23

Methods ​

_prepare() ​
ts
_prepare(): PgUnthrownPreparedQuery<{
  execute: TResult;
}>;

Defined in: packages/drizzle/src/pg-core/raw.ts:40

Returns ​

PgUnthrownPreparedQuery<{ execute: TResult; }>

execute() ​
ts
execute(placeholderValues?): AsyncResult<TResult, PgQueryError>;

Defined in: packages/drizzle/src/pg-core/raw.ts:36

Run the statement, resolving to the driver's result.

Parameters ​
ParameterType
placeholderValues?Record<string, unknown>
Returns ​

AsyncResult<TResult, PgQueryError>

getQuery() ​
ts
getQuery(): Query;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/raw.d.ts:18

Returns ​

Query

Inherited from ​

PgRaw.getQuery

getSQL() ​
ts
getSQL(): SQL<unknown>;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/raw.d.ts:17

Returns ​

SQL<unknown>

Inherited from ​

PgRaw.getSQL

shouldOmitSQLParens()? ​
ts
shouldOmitSQLParens?(): boolean;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/sql/sql.d.ts:48

Returns ​

boolean

Inherited from ​

PgRaw.shouldOmitSQLParens


PgUnthrownRefreshMaterializedView ​

Defined in: packages/drizzle/src/pg-core/refresh-materialized-view.ts:18

A refresh materialized view statement that resolves to an AsyncResult.

Extends ​

  • PgRefreshMaterializedView<TQueryResult>

Type Parameters ​

Type Parameter
TQueryResult extends PgQueryResultHKT

Constructors ​

Constructor ​
ts
new PgUnthrownRefreshMaterializedView<TQueryResult>(
   view, 
   session, 
   dialect
): PgUnthrownRefreshMaterializedView<TQueryResult>;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/refresh-materialized-view.d.ts:20

Parameters ​
ParameterType
viewPgMaterializedView
sessionPgSession
dialectPgDialect
Returns ​

PgUnthrownRefreshMaterializedView<TQueryResult>

Inherited from ​

PgRefreshMaterializedView<TQueryResult>.constructor

Properties ​

PropertyModifierTypeDefault valueDescriptionOverridesInherited fromDefined in
_readonlyobjectundefined--PgRefreshMaterializedView._node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/refresh-materialized-view.d.ts:11
_.dialectreadonly"pg"undefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/refresh-materialized-view.d.ts:12
_.resultreadonlyPgQueryResultKind<TQueryResult, never>undefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/refresh-materialized-view.d.ts:13
thenreadonlyResultThen<PgQueryResultKind<TQueryResult, never>, never>...The then that makes a query builder awaitable, resolving to a Result. Remarks Drizzle's promise and Effect trees each make their builders runnable the same way: the builder carries a then that defers to execute(). The promise tree gets it from the QueryPromise mixin, whose then is literally this.execute().then(onFulfilled, onRejected). This package cannot reuse that mixin. QueryPromise<T> declares execute(): Promise<T>, and ours returns an AsyncResult<T, PgQueryError> — so merging its type would contradict the very method it delegates to. (Its applyMixins helper is @internal and absent from drizzle's published .d.ts besides.) Each builder therefore declares this then itself, built by resultThen, with the awaited type it actually produces. Awaiting a builder yields a Result, never a rejection: execute() returns an AsyncResult, whose internal promise never rejects, and the compilation step ahead of it runs inside the same boundary — see runQuery. catch and finally are deliberately not offered: there is no rejection for them to observe. onRejected is still forwarded, exactly as AsyncResult.then forwards it, so a hypothetical internal rejection settles the await instead of hanging it.--packages/drizzle/src/pg-core/refresh-materialized-view.ts:88
[entityKind]static readonlystring"PgUnthrownRefreshMaterializedView"-PgRefreshMaterializedView.[entityKind]-packages/drizzle/src/pg-core/refresh-materialized-view.ts:21

Methods ​

concurrently() ​
ts
concurrently(): this;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/refresh-materialized-view.d.ts:21

Returns ​

this

Inherited from ​

PgRefreshMaterializedView.concurrently

execute() ​
ts
execute(placeholderValues?): AsyncResult<PgQueryResultKind<TQueryResult, never>, never>;

Defined in: packages/drizzle/src/pg-core/refresh-materialized-view.ts:80

Run the refresh, resolving to the driver's result.

The error channel is never, and here that is a judgement, not an impossibility. A refresh can raise 23505 — it repopulates a heap, and REFRESH … CONCURRENTLY (the inherited .concurrently()) requires a unique index, so a view whose own query yields duplicates violates it.

It is still a defect, by this package's "would you branch on it?" rule: a materialized view whose query produces duplicates is a bug in the view definition, which you log and 500 on — exactly what match's defect arm already does. Nobody writes a recovery path for it, and modelling it would put an arm at every refresh call site duplicating that same defect arm. Runtime and type agree either way; see runSafeQuery.

Parameters ​
ParameterType
placeholderValues?Record<string, unknown>
Returns ​

AsyncResult<PgQueryResultKind<TQueryResult, never>, never>

getSQL() ​
ts
getSQL(): SQL;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/refresh-materialized-view.d.ts:23

Returns ​

SQL

Inherited from ​

PgRefreshMaterializedView.getSQL

prepare() ​
ts
prepare(name): PgUnthrownSafePreparedQuery<PreparedQueryConfig & object>;

Defined in: packages/drizzle/src/pg-core/refresh-materialized-view.ts:57

Create a prepared statement for this query. This allows the database to remember this query for the given session and call it by name, rather than specifying the full query.

Its execute() carries the same never error channel as this builder's — see PgUnthrownSafePreparedQuery.

Postgres prepare documentation

Parameters ​
ParameterType
namestring
Returns ​

PgUnthrownSafePreparedQuery<PreparedQueryConfig & object>

toSQL() ​
ts
toSQL(): Query;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/refresh-materialized-view.d.ts:24

Returns ​

Query

Inherited from ​

PgRefreshMaterializedView.toSQL

withNoData() ​
ts
withNoData(): this;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/refresh-materialized-view.d.ts:22

Returns ​

this

Inherited from ​

PgRefreshMaterializedView.withNoData


PgUnthrownRelationalQuery ​

Defined in: packages/drizzle/src/pg-core/query.ts:34

A relational (db.query.…) query that resolves to an AsyncResult.

Extends ​

Type Parameters ​

Type ParameterDescription
TResultthe shape the relational query builds; an array for findMany, a single row or undefined for findFirst.

Constructors ​

Constructor ​
ts
new PgUnthrownRelationalQuery<TResult>(
   schema, 
   table, 
   tableConfig, 
   dialect, 
   session, 
   config, 
   mode, 
   parseJson
): PgUnthrownRelationalQuery<TResult>;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/query.d.ts:51

Parameters ​
ParameterType
schemaTablesRelationalConfig
tablePgTable
tableConfigTableRelationalConfig
dialectPgDialect
sessionPgSession
configtrue | DBQueryConfigWithComment<"many" | "one">
mode"many" | "first"
parseJsonboolean
Returns ​

PgUnthrownRelationalQuery<TResult>

Inherited from ​

PgRelationalQuery<PgUnthrownRelationalQueryHKT, TResult>.constructor

Properties ​

PropertyModifierTypeDefault valueDescriptionOverridesInherited fromDefined in
_readonlyobjectundefined--PgRelationalQuery._node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/query.d.ts:46
_.dialectreadonly"pg"undefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/query.d.ts:47
_.hktreadonlyPgUnthrownRelationalQueryHKTundefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/query.d.ts:48
_.resultreadonlyTResultundefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/query.d.ts:49
thenreadonlyResultThen<TResult, never>...The then that makes a query builder awaitable, resolving to a Result. Remarks Drizzle's promise and Effect trees each make their builders runnable the same way: the builder carries a then that defers to execute(). The promise tree gets it from the QueryPromise mixin, whose then is literally this.execute().then(onFulfilled, onRejected). This package cannot reuse that mixin. QueryPromise<T> declares execute(): Promise<T>, and ours returns an AsyncResult<T, PgQueryError> — so merging its type would contradict the very method it delegates to. (Its applyMixins helper is @internal and absent from drizzle's published .d.ts besides.) Each builder therefore declares this then itself, built by resultThen, with the awaited type it actually produces. Awaiting a builder yields a Result, never a rejection: execute() returns an AsyncResult, whose internal promise never rejects, and the compilation step ahead of it runs inside the same boundary — see runQuery. catch and finally are deliberately not offered: there is no rejection for them to observe. onRejected is still forwarded, exactly as AsyncResult.then forwards it, so a hypothetical internal rejection settles the await instead of hanging it.--packages/drizzle/src/pg-core/query.ts:95
[entityKind]static readonlystring"PgUnthrownRelationalQuery"-PgRelationalQuery.[entityKind]-packages/drizzle/src/pg-core/query.ts:38

Methods ​

execute() ​
ts
execute(placeholderValues?): AsyncResult<TResult, never>;

Defined in: packages/drizzle/src/pg-core/query.ts:89

Run the relational query, resolving to its rows.

The error channel is never — db.query.* is a read, so every failure it can hit is a defect. See runSafeQuery.

Parameters ​
ParameterType
placeholderValues?Record<string, unknown>
Returns ​

AsyncResult<TResult, never>

getSQL() ​
ts
getSQL(): SQL;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/query.d.ts:53

Returns ​

SQL

Inherited from ​

PgRelationalQuery.getSQL

prepare() ​
ts
prepare(name): PgUnthrownSafePreparedQuery<PreparedQueryConfig & object>;

Defined in: packages/drizzle/src/pg-core/query.ts:79

Create a prepared statement for this query. This allows the database to remember this query for the given session and call it by name, rather than specifying the full query.

Its execute() carries the same never error channel as this builder's — see PgUnthrownSafePreparedQuery.

Postgres prepare documentation

Parameters ​
ParameterType
namestring
Returns ​

PgUnthrownSafePreparedQuery<PreparedQueryConfig & object>

toSQL() ​
ts
toSQL(): Query;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/query.d.ts:58

Returns ​

Query

Inherited from ​

PgRelationalQuery.toSQL


PgUnthrownSelectBase ​

Defined in: packages/drizzle/src/pg-core/select.ts:127

A select query that resolves to an AsyncResult.

Remarks ​

Every chaining method comes from drizzle's PgSelectBase; this subclass adds only the execution half — _prepare, prepare, execute — plus the then that makes await db.select().from(users) yield a Result.

The error channel is never for a read: a SELECT writes nothing, so it cannot violate an integrity constraint; a database that will not answer is an infrastructure failure, which is a defect. That is enforced at runtime as well as declared — see runSafeQuery.

The exception is a select built by db.with(…) over a CTE that may write — db.$with("x").as(db.insert(t).values(…).returning()), which Postgres runs as a real INSERT. That select carries PgQueryError and is qualified exactly as the insert would be, so its 23505 is an Err rather than a defect. A CTE over raw SQL counts as writing, since its text cannot be read.

Extends ​

  • PgSelectBase<PgUnthrownSelectHKT<TError>, TTableName, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields>

Type Parameters ​

Type ParameterDefault typeDescription
TTableName extends string | undefined--
TSelection extends ColumnsSelection | undefined--
TSelectMode extends SelectMode--
TNullabilityMap extends Record<string, JoinNullability>TTableName extends string ? Record<TTableName, "not-null"> : Record<string, never>-
TDynamic extends booleanfalse-
TExcludedMethods extends stringnever-
TResult extends unknown[]SelectResult<TSelection, TSelectMode, TNullabilityMap>[]-
TSelectedFields extends ColumnsSelectionBuildSubquerySelection<Assume<TSelection, ColumnsSelection>, TNullabilityMap>-
TErrornevernever for a read, PgQueryError when the WITH list may write. Set by db.with(…), never by hand.

Constructors ​

Constructor ​
ts
new PgUnthrownSelectBase<TTableName, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields, TError>(config): PgUnthrownSelectBase<TTableName, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields, TError>;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.d.ts:87

Parameters ​
ParameterType
config{ dialect: PgDialect; distinct: | boolean | { on: ( | SQLWrapper<unknown> | PgColumn<any, PgColumnBaseConfig<any>, { }>)[]; } | undefined; fields: Record<string, unknown>; isPartialSelect: boolean; session: PgSession | undefined; table: | PgTable<TableConfig> | PgViewBase<ViewConfig<ColumnsSelection>> | SQL<unknown> | Subquery<string, Record<string, unknown>>; tagged?: boolean; withList: Subquery<string, Record<string, unknown>>[]; }
config.dialectPgDialect
config.distinct| boolean | { on: ( | SQLWrapper<unknown> | PgColumn<any, PgColumnBaseConfig<any>, { }>)[]; } | undefined
config.fieldsRecord<string, unknown>
config.isPartialSelectboolean
config.sessionPgSession | undefined
config.table| PgTable<TableConfig> | PgViewBase<ViewConfig<ColumnsSelection>> | SQL<unknown> | Subquery<string, Record<string, unknown>>
config.tagged?boolean
config.withListSubquery<string, Record<string, unknown>>[]
Returns ​

PgUnthrownSelectBase<TTableName, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields, TError>

Inherited from ​

PgSelectBase<PgUnthrownSelectHKT<TError>, TTableName, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields>.constructor

Properties ​

PropertyModifierTypeDefault valueDescriptionOverridesInherited fromDefined in
_readonlyobjectundefined--PgSelectBase._node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.d.ts:66
_.configreadonlyPgSelectConfigundefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.d.ts:77
_.dialectreadonly"pg"undefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.d.ts:67
_.dynamicreadonlyTDynamicundefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.d.ts:73
_.excludedMethodsreadonlyTExcludedMethodsundefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.d.ts:74
_.hktreadonlyPgUnthrownSelectHKTundefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.d.ts:68
_.nullabilityMapreadonlyTNullabilityMapundefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.d.ts:72
_.resultreadonlyTResultundefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.d.ts:75
_.selectedFieldsreadonlyTSelectedFieldsundefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.d.ts:76
_.selectionreadonlyTSelectionundefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.d.ts:70
_.selectModereadonlyTSelectModeundefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.d.ts:71
_.tableNamereadonlyTTableNameundefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.d.ts:69
crossJoinpublicPgSelectCrossJoinFn<PgUnthrownSelectBase<TTableName, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields, TError>, TDynamic, false>undefinedExecutes a cross join operation by combining rows from two tables into a new table. Calling this method retrieves all rows from both main and joined tables, merging all rows from each table. See docs: https://orm.drizzle.team/docs/joins#cross-join Param table the table to join. Example // Select all users, each user with every pet const usersWithPets: { user: User; pets: Pet; }[] = await db.select() .from(users) .crossJoin(pets) // Select userId and petId const usersIdsAndPetIds: { userId: number; petId: number; }[] = await db.select({ userId: users.id, petId: pets.id, }) .from(users) .crossJoin(pets)-PgSelectBase.crossJoinnode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.d.ts:286
crossJoinLateralpublicPgSelectCrossJoinFn<PgUnthrownSelectBase<TTableName, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields, TError>, TDynamic, true>undefinedExecutes a cross join lateral operation by combining rows from two queries into a new table. A lateral join allows the right-hand expression to refer to columns from the left-hand side. Calling this method retrieves all rows from both main and joined queries, merging all rows from each query. See docs: https://orm.drizzle.team/docs/joins#cross-join-lateral Param table the query to join. Example // Pair each city with every row its correlated subquery produces; cities with none are dropped const sq = db.select({ userId: users.id }).from(users).where(eq(users.cityId, cities.id)).as('sq'); const rows: { cities: City; sq: { userId: number } }[] = await db.select() .from(cities) .crossJoinLateral(sq)-PgSelectBase.crossJoinLateralnode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.d.ts:309
exceptpublic<TValue>(rightSelection) => PgSelectWithout<PgUnthrownSelectBase<TTableName, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields, TError>, TDynamic, PgSetOperatorExcludedMethods, true>undefinedAdds except set operator to the query. Calling this method will retrieve all unique rows from the left query, except for the rows that are present in the result set of the right query. See docs: https://orm.drizzle.team/docs/set-operations#except Example // Select all courses offered in department A but not in department B await db.select({ courseName: depA.courseName }) .from(depA) .except( db.select({ courseName: depB.courseName }).from(depB) ); // or import { except } from 'drizzle-orm/pg-core' await except( db.select({ courseName: depA.courseName }).from(depA), db.select({ courseName: depB.courseName }).from(depB) );-PgSelectBase.exceptnode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.d.ts:455
exceptAllpublic<TValue>(rightSelection) => PgSelectWithout<PgUnthrownSelectBase<TTableName, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields, TError>, TDynamic, PgSetOperatorExcludedMethods, true>undefinedAdds except all set operator to the query. Calling this method will retrieve all rows from the left query, except for the rows that are present in the result set of the right query. See docs: https://orm.drizzle.team/docs/set-operations#except-all Example // Select all products that are ordered by regular customers but not by VIP customers await db.select({ productId: regularCustomerOrders.productId, quantityOrdered: regularCustomerOrders.quantityOrdered, }) .from(regularCustomerOrders) .exceptAll( db.select({ productId: vipCustomerOrders.productId, quantityOrdered: vipCustomerOrders.quantityOrdered, }) .from(vipCustomerOrders) ); // or import { exceptAll } from 'drizzle-orm/pg-core' await exceptAll( db.select({ productId: regularCustomerOrders.productId, quantityOrdered: regularCustomerOrders.quantityOrdered }) .from(regularCustomerOrders), db.select({ productId: vipCustomerOrders.productId, quantityOrdered: vipCustomerOrders.quantityOrdered }) .from(vipCustomerOrders) );-PgSelectBase.exceptAllnode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.d.ts:496
fullJoinpublicPgSelectJoinFn<PgUnthrownSelectBase<TTableName, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields, TError>, TDynamic, "full", false>undefinedExecutes a full join operation by combining rows from two tables into a new table. Calling this method retrieves all rows from both main and joined tables, merging rows with matching values and filling in null for non-matching columns. See docs: https://orm.drizzle.team/docs/joins#full-join Param table the table to join. Param on the on clause. Example // Select all users and their pets const usersWithPets: { user: User | null; pets: Pet | null; }[] = await db.select() .from(users) .fullJoin(pets, eq(users.id, pets.ownerId)) // Select userId and petId const usersIdsAndPetIds: { userId: number | null; petId: number | null; }[] = await db.select({ userId: users.id, petId: pets.id, }) .from(users) .fullJoin(pets, eq(users.id, pets.ownerId))-PgSelectBase.fullJoinnode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.d.ts:259
innerJoinpublicPgSelectJoinFn<PgUnthrownSelectBase<TTableName, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields, TError>, TDynamic, "inner", false>undefinedExecutes an inner join operation, creating a new table by combining rows from two tables that have matching values. Calling this method retrieves rows that have corresponding entries in both joined tables. Rows without matching entries in either table are excluded, resulting in a table that includes only matching pairs. See docs: https://orm.drizzle.team/docs/joins#inner-join Param table the table to join. Param on the on clause. Example // Select all users and their pets const usersWithPets: { user: User; pets: Pet; }[] = await db.select() .from(users) .innerJoin(pets, eq(users.id, pets.ownerId)) // Select userId and petId const usersIdsAndPetIds: { userId: number; petId: number; }[] = await db.select({ userId: users.id, petId: pets.id, }) .from(users) .innerJoin(pets, eq(users.id, pets.ownerId))-PgSelectBase.innerJoinnode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.d.ts:207
innerJoinLateralpublicPgSelectJoinFn<PgUnthrownSelectBase<TTableName, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields, TError>, TDynamic, "inner", true>undefinedExecutes an inner join lateral operation, creating a new table by combining rows from two queries that have matching values. A lateral join allows the right-hand expression to refer to columns from the left-hand side. Calling this method retrieves rows that have corresponding entries in both joined tables. Rows without matching entries in either table are excluded, resulting in a table that includes only matching pairs. See docs: https://orm.drizzle.team/docs/joins#inner-join-lateral Param table the subquery to join. Param on the on clause. Example // Select only the cities that have users, along with those users const sq = db.select({ userId: users.id }).from(users).where(eq(users.cityId, cities.id)).as('sq'); const rows: { cities: City; sq: { userId: number } }[] = await db.select() .from(cities) .innerJoinLateral(sq, sqltrue)-PgSelectBase.innerJoinLateralnode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.d.ts:231
intersectpublic<TValue>(rightSelection) => PgSelectWithout<PgUnthrownSelectBase<TTableName, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields, TError>, TDynamic, PgSetOperatorExcludedMethods, true>undefinedAdds intersect set operator to the query. Calling this method will retain only the rows that are present in both result sets and eliminate duplicates. See docs: https://orm.drizzle.team/docs/set-operations#intersect Example // Select course names that are offered in both departments A and B await db.select({ courseName: depA.courseName }) .from(depA) .intersect( db.select({ courseName: depB.courseName }).from(depB) ); // or import { intersect } from 'drizzle-orm/pg-core' await intersect( db.select({ courseName: depA.courseName }).from(depA), db.select({ courseName: depB.courseName }).from(depB) );-PgSelectBase.intersectnode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.d.ts:388
intersectAllpublic<TValue>(rightSelection) => PgSelectWithout<PgUnthrownSelectBase<TTableName, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields, TError>, TDynamic, PgSetOperatorExcludedMethods, true>undefinedAdds intersect all set operator to the query. Calling this method will retain only the rows that are present in both result sets including all duplicates. See docs: https://orm.drizzle.team/docs/set-operations#intersect-all Example // Select all products and quantities that are ordered by both regular and VIP customers await db.select({ productId: regularCustomerOrders.productId, quantityOrdered: regularCustomerOrders.quantityOrdered }) .from(regularCustomerOrders) .intersectAll( db.select({ productId: vipCustomerOrders.productId, quantityOrdered: vipCustomerOrders.quantityOrdered }) .from(vipCustomerOrders) ); // or import { intersectAll } from 'drizzle-orm/pg-core' await intersectAll( db.select({ productId: regularCustomerOrders.productId, quantityOrdered: regularCustomerOrders.quantityOrdered }) .from(regularCustomerOrders), db.select({ productId: vipCustomerOrders.productId, quantityOrdered: vipCustomerOrders.quantityOrdered }) .from(vipCustomerOrders) );-PgSelectBase.intersectAllnode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.d.ts:429
leftJoinpublicPgSelectJoinFn<PgUnthrownSelectBase<TTableName, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields, TError>, TDynamic, "left", false>undefinedExecutes a left join operation by adding another table to the current query. Calling this method associates each row of the table with the corresponding row from the joined table, if a match is found. If no matching row exists, it sets all columns of the joined table to null. See docs: https://orm.drizzle.team/docs/joins#left-join Param table the table to join. Param on the on clause. Example // Select all users and their pets const usersWithPets: { user: User; pets: Pet | null; }[] = await db.select() .from(users) .leftJoin(pets, eq(users.id, pets.ownerId)) // Select userId and petId const usersIdsAndPetIds: { userId: number; petId: number | null; }[] = await db.select({ userId: users.id, petId: pets.id, }) .from(users) .leftJoin(pets, eq(users.id, pets.ownerId))-PgSelectBase.leftJoinnode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.d.ts:127
leftJoinLateralpublicPgSelectJoinFn<PgUnthrownSelectBase<TTableName, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields, TError>, TDynamic, "left", true>undefinedExecutes a left join lateral operation by adding subquery to the current query. A lateral join allows the right-hand expression to refer to columns from the left-hand side. Calling this method associates each row of the table with the corresponding row from the joined table, if a match is found. If no matching row exists, it sets all columns of the joined table to null. See docs: https://orm.drizzle.team/docs/joins#left-join-lateral Param table the subquery to join. Param on the on clause. Example // Select every city and, for each, the users that live in it const sq = db.select({ userId: users.id }).from(users).where(eq(users.cityId, cities.id)).as('sq'); const rows: { cities: City; sq: { userId: number } | null }[] = await db.select() .from(cities) .leftJoinLateral(sq, sqltrue)-PgSelectBase.leftJoinLateralnode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.d.ts:151
rightJoinpublicPgSelectJoinFn<PgUnthrownSelectBase<TTableName, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields, TError>, TDynamic, "right", false>undefinedExecutes a right join operation by adding another table to the current query. Calling this method associates each row of the joined table with the corresponding row from the main table, if a match is found. If no matching row exists, it sets all columns of the main table to null. See docs: https://orm.drizzle.team/docs/joins#right-join Param table the table to join. Param on the on clause. Example // Select all users and their pets const usersWithPets: { user: User | null; pets: Pet; }[] = await db.select() .from(users) .rightJoin(pets, eq(users.id, pets.ownerId)) // Select userId and petId const usersIdsAndPetIds: { userId: number | null; petId: number; }[] = await db.select({ userId: users.id, petId: pets.id, }) .from(users) .rightJoin(pets, eq(users.id, pets.ownerId))-PgSelectBase.rightJoinnode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.d.ts:179
thenreadonlyResultThen<TResult, TError>...The then that makes a query builder awaitable, resolving to a Result. Remarks Drizzle's promise and Effect trees each make their builders runnable the same way: the builder carries a then that defers to execute(). The promise tree gets it from the QueryPromise mixin, whose then is literally this.execute().then(onFulfilled, onRejected). This package cannot reuse that mixin. QueryPromise<T> declares execute(): Promise<T>, and ours returns an AsyncResult<T, PgQueryError> — so merging its type would contradict the very method it delegates to. (Its applyMixins helper is @internal and absent from drizzle's published .d.ts besides.) Each builder therefore declares this then itself, built by resultThen, with the awaited type it actually produces. Awaiting a builder yields a Result, never a rejection: execute() returns an AsyncResult, whose internal promise never rejects, and the compilation step ahead of it runs inside the same boundary — see runQuery. catch and finally are deliberately not offered: there is no rejection for them to observe. onRejected is still forwarded, exactly as AsyncResult.then forwards it, so a hypothetical internal rejection settles the await instead of hanging it.--packages/drizzle/src/pg-core/select.ts:246
unionpublic<TValue>(rightSelection) => PgSelectWithout<PgUnthrownSelectBase<TTableName, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields, TError>, TDynamic, PgSetOperatorExcludedMethods, true>undefinedAdds union set operator to the query. Calling this method will combine the result sets of the select statements and remove any duplicate rows that appear across them. See docs: https://orm.drizzle.team/docs/set-operations#union Example // Select all unique names from customers and users tables await db.select({ name: users.name }) .from(users) .union( db.select({ name: customers.name }).from(customers) ); // or import { union } from 'drizzle-orm/pg-core' await union( db.select({ name: users.name }).from(users), db.select({ name: customers.name }).from(customers) );-PgSelectBase.unionnode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.d.ts:336
unionAllpublic<TValue>(rightSelection) => PgSelectWithout<PgUnthrownSelectBase<TTableName, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields, TError>, TDynamic, PgSetOperatorExcludedMethods, true>undefinedAdds union all set operator to the query. Calling this method will combine the result-set of the select statements and keep all duplicate rows that appear across them. See docs: https://orm.drizzle.team/docs/set-operations#union-all Example // Select all transaction ids from both online and in-store sales await db.select({ transaction: onlineSales.transactionId }) .from(onlineSales) .unionAll( db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales) ); // or import { unionAll } from 'drizzle-orm/pg-core' await unionAll( db.select({ transaction: onlineSales.transactionId }).from(onlineSales), db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales) );-PgSelectBase.unionAllnode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.d.ts:362
[entityKind]static readonlystring"PgUnthrownSelect"-PgSelectBase.[entityKind]-packages/drizzle/src/pg-core/select.ts:153

Methods ​

$dynamic() ​
ts
$dynamic(): PgSelectDynamic<PgUnthrownSelectBase<TTableName, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields, TError>>;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.d.ts:649

Returns ​

PgSelectDynamic<PgUnthrownSelectBase<TTableName, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields, TError>>

Inherited from ​

PgSelectBase.$dynamic

$withCache() ​
ts
$withCache(config?): this;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.d.ts:650

Parameters ​
ParameterType
config?| false | { autoInvalidate?: boolean; config?: CacheConfig; tag?: string; }
Returns ​

this

Inherited from ​

PgSelectBase.$withCache

as() ​
ts
as<TAlias>(alias): SubqueryWithSelection<TSelectedFields, TAlias>;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.d.ts:648

Type Parameters ​
Type Parameter
TAlias extends string
Parameters ​
ParameterType
aliasTAlias
Returns ​

SubqueryWithSelection<TSelectedFields, TAlias>

Inherited from ​

PgSelectBase.as

comment() ​
ts
comment(comment): PgSelectWithout<PgUnthrownSelectBase<TTableName, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields, TError>, TDynamic, "comment">;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.d.ts:645

Attach sqlcommenter comment to a query

Parameters ​
ParameterType
commentCommentInput
Returns ​

PgSelectWithout<PgUnthrownSelectBase<TTableName, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields, TError>, TDynamic, "comment">

Inherited from ​

PgSelectBase.comment

execute() ​
ts
execute(placeholderValues?): AsyncResult<TResult, TError>;

Defined in: packages/drizzle/src/pg-core/select.ts:233

Run the query, resolving to the selected rows.

The error channel is never for a read — every failure a read can hit is a defect, and runSafeQuery is what makes that true at runtime, not just in the type. A select over a writing CTE carries PgQueryError.

Parameters ​
ParameterType
placeholderValues?Record<string, unknown>
Returns ​

AsyncResult<TResult, TError>

for() ​
ts
for(strength, config?): PgSelectWithout<PgUnthrownSelectBase<TTableName, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields, TError>, TDynamic, "for">;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.d.ts:641

Adds a for clause to the query.

Calling this method will specify a lock strength for this query that controls how strictly it acquires exclusive access to the rows being queried.

See docs: https://www.postgresql.org/docs/current/sql-select.html#SQL-FOR-UPDATE-SHARE

Parameters ​
ParameterTypeDescription
strengthLockStrengththe lock strength.
config?LockConfigthe lock configuration.
Returns ​

PgSelectWithout<PgUnthrownSelectBase<TTableName, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields, TError>, TDynamic, "for">

Inherited from ​

PgSelectBase.for

getSQL() ​
ts
getSQL(): SQL;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.d.ts:646

Returns ​

SQL

Inherited from ​

PgSelectBase.getSQL

groupBy() ​
Call Signature ​
ts
groupBy(builder): PgSelectWithout<PgUnthrownSelectBase<TTableName, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields, TError>, TDynamic, "groupBy">;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.d.ts:569

Adds a group by clause to the query.

Calling this method will group rows that have the same values into summary rows, often used for aggregation purposes.

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

Parameters ​
ParameterType
builder(aliases) => ValueOrArray< | SQL<unknown> | PgColumn<any, PgColumnBaseConfig<any>, { }> | Aliased<unknown>>
Returns ​

PgSelectWithout<PgUnthrownSelectBase<TTableName, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields, TError>, TDynamic, "groupBy">

Example ​
ts
// Group and count people by their last names
await db.select({
   lastName: people.lastName,
   count: sql<number>`cast(count(*) as int)`
})
  .from(people)
  .groupBy(people.lastName);
Inherited from ​

PgSelectBase.groupBy

Call Signature ​
ts
groupBy(...columns): PgSelectWithout<PgUnthrownSelectBase<TTableName, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields, TError>, TDynamic, "groupBy">;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.d.ts:570

Adds a group by clause to the query.

Calling this method will group rows that have the same values into summary rows, often used for aggregation purposes.

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

Parameters ​
ParameterType
...columns( | SQL<unknown> | PgColumn<any, PgColumnBaseConfig<any>, { }> | Aliased<unknown>)[]
Returns ​

PgSelectWithout<PgUnthrownSelectBase<TTableName, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields, TError>, TDynamic, "groupBy">

Example ​
ts
// Group and count people by their last names
await db.select({
   lastName: people.lastName,
   count: sql<number>`cast(count(*) as int)`
})
  .from(people)
  .groupBy(people.lastName);
Inherited from ​

PgSelectBase.groupBy

having() ​
ts
having(having): PgSelectWithout<PgUnthrownSelectBase<TTableName, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields, TError>, TDynamic, "having">;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.d.ts:549

Adds a having clause to the query.

Calling this method will select only those rows that fulfill a specified condition. It is typically used with aggregate functions to filter the aggregated data based on a specified condition.

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

Parameters ​
ParameterTypeDescription
having| SQL<unknown> | ((aliases) => SQL<unknown> | undefined) | undefinedthe having clause.
Returns ​

PgSelectWithout<PgUnthrownSelectBase<TTableName, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields, TError>, TDynamic, "having">

Example ​
ts
// Select all brands with more than one car
await db.select({
	brand: cars.brand,
	count: sql<number>`cast(count(${cars.id}) as int)`,
})
  .from(cars)
  .groupBy(cars.brand)
  .having(({ count }) => gt(count, 1));
Inherited from ​

PgSelectBase.having

limit() ​
ts
limit(limit): PgSelectWithout<PgUnthrownSelectBase<TTableName, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields, TError>, TDynamic, "limit">;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.d.ts:613

Adds a limit clause to the query.

Calling this method will set the maximum number of rows that will be returned by this query.

See docs: https://orm.drizzle.team/docs/select#limit--offset

Parameters ​
ParameterTypeDescription
limitnumber | Placeholder<string, any>the limit clause.
Returns ​

PgSelectWithout<PgUnthrownSelectBase<TTableName, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields, TError>, TDynamic, "limit">

Example ​
ts
// Get the first 10 people from this query.
await db.select().from(people).limit(10);
Inherited from ​

PgSelectBase.limit

offset() ​
ts
offset(offset): PgSelectWithout<PgUnthrownSelectBase<TTableName, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields, TError>, TDynamic, "offset">;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.d.ts:630

Adds an offset clause to the query.

Calling this method will skip a number of rows when returning results from this query.

See docs: https://orm.drizzle.team/docs/select#limit--offset

Parameters ​
ParameterTypeDescription
offsetnumber | Placeholder<string, any>the offset clause.
Returns ​

PgSelectWithout<PgUnthrownSelectBase<TTableName, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields, TError>, TDynamic, "offset">

Example ​
ts
// Get the 10th-20th people from this query.
await db.select().from(people).offset(10).limit(10);
Inherited from ​

PgSelectBase.offset

orderBy() ​
Call Signature ​
ts
orderBy(builder): PgSelectWithout<PgUnthrownSelectBase<TTableName, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields, TError>, TDynamic, "orderBy">;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.d.ts:595

Adds an order by clause to the query.

Calling this method will sort the result-set in ascending or descending order. By default, the sort order is ascending.

See docs: https://orm.drizzle.team/docs/select#order-by

Parameters ​
ParameterType
builder(aliases) => ValueOrArray< | SQL<unknown> | PgColumn<any, PgColumnBaseConfig<any>, { }> | Aliased<unknown>>
Returns ​

PgSelectWithout<PgUnthrownSelectBase<TTableName, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields, TError>, TDynamic, "orderBy">

Example ​
// Select cars ordered by year
await db.select().from(cars).orderBy(cars.year);

You can specify whether results are in ascending or descending order with the asc() and desc() operators.

ts
// Select cars ordered by year in descending order
await db.select().from(cars).orderBy(desc(cars.year));

// Select cars ordered by year and price
await db.select().from(cars).orderBy(asc(cars.year), desc(cars.price));
Inherited from ​

PgSelectBase.orderBy

Call Signature ​
ts
orderBy(...columns): PgSelectWithout<PgUnthrownSelectBase<TTableName, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields, TError>, TDynamic, "orderBy">;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.d.ts:596

Adds an order by clause to the query.

Calling this method will sort the result-set in ascending or descending order. By default, the sort order is ascending.

See docs: https://orm.drizzle.team/docs/select#order-by

Parameters ​
ParameterType
...columns( | SQL<unknown> | PgColumn<any, PgColumnBaseConfig<any>, { }> | Aliased<unknown>)[]
Returns ​

PgSelectWithout<PgUnthrownSelectBase<TTableName, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields, TError>, TDynamic, "orderBy">

Example ​
// Select cars ordered by year
await db.select().from(cars).orderBy(cars.year);

You can specify whether results are in ascending or descending order with the asc() and desc() operators.

ts
// Select cars ordered by year in descending order
await db.select().from(cars).orderBy(desc(cars.year));

// Select cars ordered by year and price
await db.select().from(cars).orderBy(asc(cars.year), desc(cars.price));
Inherited from ​

PgSelectBase.orderBy

prepare() ​
ts
prepare(name): PgUnthrownSelectPreparedQuery<PreparedQueryConfig & object, TError>;

Defined in: packages/drizzle/src/pg-core/select.ts:220

Create a prepared statement for this query. This allows the database to remember this query for the given session and call it by name, rather than specifying the full query.

Its execute() carries the same error channel as this builder's — never for a read, see PgUnthrownSafePreparedQuery.

Postgres prepare documentation

Parameters ​
ParameterType
namestring
Returns ​

PgUnthrownSelectPreparedQuery<PreparedQueryConfig & object, TError>

toSQL() ​
ts
toSQL(): Query;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.d.ts:647

Returns ​

Query

Inherited from ​

PgSelectBase.toSQL

where() ​
ts
where(where): PgSelectWithout<PgUnthrownSelectBase<TTableName, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields, TError>, TDynamic, "where">;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.d.ts:526

Adds a where clause to the query.

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

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

Parameters ​
ParameterTypeDescription
where| SQL<unknown> | ((aliases) => SQL<unknown> | undefined) | undefinedthe where clause.
Returns ​

PgSelectWithout<PgUnthrownSelectBase<TTableName, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields, TError>, TDynamic, "where">

Example ​

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

ts
// Select all cars with green color
await db.select().from(cars).where(eq(cars.color, 'green'));
// or
await db.select().from(cars).where(sql`${cars.color} = 'green'`)

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

ts
// Select all BMW cars with a green color
await db.select().from(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));

// Select all cars with the green or blue color
await db.select().from(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
Inherited from ​

PgSelectBase.where


PgUnthrownUpdateBase ​

Defined in: packages/drizzle/src/pg-core/update.ts:60

An update query that resolves to an AsyncResult.

Extends ​

  • PgUpdateBase<PgUnthrownUpdateHKT, TTable, TQueryResult, TFrom, TSelectedFields, TReturning, TNullabilityMap, TJoins, TDynamic, TExcludedMethods>

Type Parameters ​

Type ParameterDefault type
TTable extends PgTable-
TQueryResult extends PgQueryResultHKT-
TFrom extends PgTable | Subquery | PgViewBase | SQL | undefinedundefined
TSelectedFields extends ColumnsSelection | undefinedundefined
TReturning extends Record<string, unknown> | undefinedundefined
TNullabilityMap extends Record<string, JoinNullability>Record<TTable["_"]["name"], "not-null">
TJoins extends Join[][]
TDynamic extends booleanfalse
TExcludedMethods extends stringnever

Constructors ​

Constructor ​
ts
new PgUnthrownUpdateBase<TTable, TQueryResult, TFrom, TSelectedFields, TReturning, TNullabilityMap, TJoins, TDynamic, TExcludedMethods>(
   table, 
   set, 
   session, 
   dialect, 
   withList?
): PgUnthrownUpdateBase<TTable, TQueryResult, TFrom, TSelectedFields, TReturning, TNullabilityMap, TJoins, TDynamic, TExcludedMethods>;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/update.d.ts:119

Parameters ​
ParameterType
tableTTable
setUpdateSet
sessionPgSession
dialectPgDialect
withList?Subquery<string, Record<string, unknown>>[]
Returns ​

PgUnthrownUpdateBase<TTable, TQueryResult, TFrom, TSelectedFields, TReturning, TNullabilityMap, TJoins, TDynamic, TExcludedMethods>

Inherited from ​

PgUpdateBase<PgUnthrownUpdateHKT, TTable, TQueryResult, TFrom, TSelectedFields, TReturning, TNullabilityMap, TJoins, TDynamic, TExcludedMethods>.constructor

Properties ​

PropertyModifierTypeDefault valueDescriptionOverridesInherited fromDefined in
_readonlyobjectundefined--PgUpdateBase._node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/update.d.ts:97
_.dialectreadonly"pg"undefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/update.d.ts:98
_.dynamicreadonlyTDynamicundefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/update.d.ts:107
_.excludedMethodsreadonlyTExcludedMethodsundefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/update.d.ts:108
_.fromreadonlyTFromundefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/update.d.ts:104
_.hktreadonlyPgUnthrownUpdateHKTundefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/update.d.ts:99
_.joinsreadonlyTJoinsundefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/update.d.ts:101
_.nullabilityMapreadonlyTNullabilityMapundefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/update.d.ts:102
_.queryResultreadonlyTQueryResultundefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/update.d.ts:103
_.resultreadonlyTReturning extends undefined ? PgQueryResultKind<TQueryResult, never> : TReturning[]undefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/update.d.ts:109
_.returningreadonlyTReturningundefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/update.d.ts:106
_.selectedFieldsreadonlyTSelectedFieldsundefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/update.d.ts:105
_.tablereadonlyTTableundefined---node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/update.d.ts:100
fullJoinpublicPgUpdateJoinFn<PgUnthrownUpdateBase<TTable, TQueryResult, TFrom, TSelectedFields, TReturning, TNullabilityMap, TJoins, TDynamic, TExcludedMethods>, TDynamic, "full">undefined--PgUpdateBase.fullJoinnode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/update.d.ts:126
innerJoinpublicPgUpdateJoinFn<PgUnthrownUpdateBase<TTable, TQueryResult, TFrom, TSelectedFields, TReturning, TNullabilityMap, TJoins, TDynamic, TExcludedMethods>, TDynamic, "inner">undefined--PgUpdateBase.innerJoinnode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/update.d.ts:125
leftJoinpublicPgUpdateJoinFn<PgUnthrownUpdateBase<TTable, TQueryResult, TFrom, TSelectedFields, TReturning, TNullabilityMap, TJoins, TDynamic, TExcludedMethods>, TDynamic, "left">undefined--PgUpdateBase.leftJoinnode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/update.d.ts:123
rightJoinpublicPgUpdateJoinFn<PgUnthrownUpdateBase<TTable, TQueryResult, TFrom, TSelectedFields, TReturning, TNullabilityMap, TJoins, TDynamic, TExcludedMethods>, TDynamic, "right">undefined--PgUpdateBase.rightJoinnode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/update.d.ts:124
thenreadonlyResultThen<UpdateResult<TQueryResult, TReturning>>...The then that makes a query builder awaitable, resolving to a Result. Remarks Drizzle's promise and Effect trees each make their builders runnable the same way: the builder carries a then that defers to execute(). The promise tree gets it from the QueryPromise mixin, whose then is literally this.execute().then(onFulfilled, onRejected). This package cannot reuse that mixin. QueryPromise<T> declares execute(): Promise<T>, and ours returns an AsyncResult<T, PgQueryError> — so merging its type would contradict the very method it delegates to. (Its applyMixins helper is @internal and absent from drizzle's published .d.ts besides.) Each builder therefore declares this then itself, built by resultThen, with the awaited type it actually produces. Awaiting a builder yields a Result, never a rejection: execute() returns an AsyncResult, whose internal promise never rejects, and the compilation step ahead of it runs inside the same boundary — see runQuery. catch and finally are deliberately not offered: there is no rejection for them to observe. onRejected is still forwarded, exactly as AsyncResult.then forwards it, so a hypothetical internal rejection settles the await instead of hanging it.--packages/drizzle/src/pg-core/update.ts:134
[entityKind]static readonlystring"PgUnthrownUpdate"-PgUpdateBase.[entityKind]-packages/drizzle/src/pg-core/update.ts:82

Methods ​

$dynamic() ​
ts
$dynamic(): PgUnthrownUpdateBase<Assume<TTable, PgTable<TableConfig>>>;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/update.d.ts:191

Returns ​

PgUnthrownUpdateBase<Assume<TTable, PgTable<TableConfig>>>

Inherited from ​

PgUpdateBase.$dynamic

comment() ​
ts
comment(comment): PgUpdateWithout<PgUnthrownUpdateBase<TTable, TQueryResult, TFrom, TSelectedFields, TReturning, TNullabilityMap, TJoins, TDynamic, TExcludedMethods>, TDynamic, "comment">;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/update.d.ts:188

Attach sqlcommenter comment to a query

Parameters ​
ParameterType
commentCommentInput
Returns ​

PgUpdateWithout<PgUnthrownUpdateBase<TTable, TQueryResult, TFrom, TSelectedFields, TReturning, TNullabilityMap, TJoins, TDynamic, TExcludedMethods>, TDynamic, "comment">

Inherited from ​

PgUpdateBase.comment

execute() ​
ts
execute(placeholderValues?): AsyncResult<UpdateResult<TQueryResult, TReturning>, PgQueryError>;

Defined in: packages/drizzle/src/pg-core/update.ts:126

Run the update, resolving to its result or a PgQueryError.

Parameters ​
ParameterType
placeholderValues?Record<string, unknown>
Returns ​

AsyncResult<UpdateResult<TQueryResult, TReturning>, PgQueryError>

from() ​
ts
from<TFrom>(source): PgUpdateWithJoins<this, TDynamic, TFrom>;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/update.d.ts:120

Type Parameters ​
Type Parameter
TFrom extends | PgTable<TableConfig> | PgViewBase<ViewConfig<ColumnsSelection>> | SQL<unknown> | Subquery<string, Record<string, unknown>>
Parameters ​
ParameterType
sourceCheckTableLikeSelection<TFrom>
Returns ​

PgUpdateWithJoins<this, TDynamic, TFrom>

Inherited from ​

PgUpdateBase.from

getSQL() ​
ts
getSQL(): SQL;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/update.d.ts:189

Returns ​

SQL

Inherited from ​

PgUpdateBase.getSQL

prepare() ​
ts
prepare(name): PgUnthrownPreparedQuery<PreparedQueryConfig & object>;

Defined in: packages/drizzle/src/pg-core/update.ts:117

Create a prepared statement for this query. This allows the database to remember this query for the given session and call it by name, rather than specifying the full query.

Postgres prepare documentation

Parameters ​
ParameterType
namestring
Returns ​

PgUnthrownPreparedQuery<PreparedQueryConfig & object>

returning() ​
Call Signature ​
ts
returning(): PgUpdateWithout<PgUpdateKind<PgUnthrownUpdateHKT, TTable, TQueryResult, TFrom, Equal<TJoins, []> extends true ? TTable["_"]["columns"] : { [K in string | number | symbol]: (Record<TTable["_"]["name"], TTable["_"]["columns"]> & { [K in string | number | symbol as (...)[(...)]["table"]["_"]["name"]]: (...)[(...)]["table"]["_"]["columns"] })[K] }, SelectPartialResult<AccumulateToResult<PgUnthrownUpdateBase<TTable, TQueryResult, TFrom, TSelectedFields, TReturning, TNullabilityMap, TJoins, TDynamic, TExcludedMethods>, "single", TJoins, GetSelectTableSelection<TTable>>, TNullabilityMap>, TNullabilityMap, TJoins, TDynamic, TExcludedMethods>, TDynamic>;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/update.d.ts:183

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 ​

PgUpdateWithout<PgUpdateKind<PgUnthrownUpdateHKT, TTable, TQueryResult, TFrom, Equal<TJoins, []> extends true ? TTable["_"]["columns"] : { [K in string | number | symbol]: (Record<TTable["_"]["name"], TTable["_"]["columns"]> & { [K in string | number | symbol as (...)[(...)]["table"]["_"]["name"]]: (...)[(...)]["table"]["_"]["columns"] })[K] }, SelectPartialResult<AccumulateToResult<PgUnthrownUpdateBase<TTable, TQueryResult, TFrom, TSelectedFields, TReturning, TNullabilityMap, TJoins, TDynamic, TExcludedMethods>, "single", TJoins, GetSelectTableSelection<TTable>>, TNullabilityMap>, TNullabilityMap, TJoins, TDynamic, TExcludedMethods>, TDynamic>

Example ​
ts
// 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 });
Inherited from ​

PgUpdateBase.returning

Call Signature ​
ts
returning<TSelectedFields>(fields): PgUpdateWithout<PgUpdateKind<PgUnthrownUpdateHKT, TTable, TQueryResult, TFrom, TSelectedFields, SelectPartialResult<AccumulateToResult<PgUnthrownUpdateBase<TTable, TQueryResult, TFrom, TSelectedFields, TReturning, TNullabilityMap, TJoins, TDynamic, TExcludedMethods>, "partial", TJoins, TSelectedFields>, TNullabilityMap>, TNullabilityMap, TJoins, TDynamic, TExcludedMethods>, TDynamic, "returning">;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/update.d.ts:184

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 ​
Type Parameter
TSelectedFields extends SelectedFields
Parameters ​
ParameterType
fieldsTSelectedFields
Returns ​

PgUpdateWithout<PgUpdateKind<PgUnthrownUpdateHKT, TTable, TQueryResult, TFrom, TSelectedFields, SelectPartialResult<AccumulateToResult<PgUnthrownUpdateBase<TTable, TQueryResult, TFrom, TSelectedFields, TReturning, TNullabilityMap, TJoins, TDynamic, TExcludedMethods>, "partial", TJoins, TSelectedFields>, TNullabilityMap>, TNullabilityMap, TJoins, TDynamic, TExcludedMethods>, TDynamic, "returning">

Example ​
ts
// 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 });
Inherited from ​

PgUpdateBase.returning

shouldOmitSQLParens()? ​
ts
shouldOmitSQLParens?(): boolean;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/sql/sql.d.ts:48

Returns ​

boolean

Inherited from ​

PgUpdateBase.shouldOmitSQLParens

toSQL() ​
ts
toSQL(): Query;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/update.d.ts:190

Returns ​

Query

Inherited from ​

PgUpdateBase.toSQL

where() ​
ts
where(where): PgUpdateWithout<PgUnthrownUpdateBase<TTable, TQueryResult, TFrom, TSelectedFields, TReturning, TNullabilityMap, TJoins, TDynamic, TExcludedMethods>, TDynamic, "where">;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/update.d.ts:160

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 ​
ParameterTypeDescription
whereSQL<unknown> | undefinedthe 'where' clause.
Returns ​

PgUpdateWithout<PgUnthrownUpdateBase<TTable, TQueryResult, TFrom, TSelectedFields, TReturning, TNullabilityMap, TJoins, TDynamic, TExcludedMethods>, TDynamic, "where">

Example ​

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

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

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

ts
// Update all BMW cars with a green color
await 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
await db.update(cars).set({ color: 'red' })
  .where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
Inherited from ​

PgUpdateBase.where


PgUnthrownDeleteHKT ​

Defined in: packages/drizzle/src/pg-core/delete.ts:37

The higher-kinded type that keeps every chained delete method returning an unthrown builder rather than drizzle's own.

Remarks ​

See PgUnthrownSelectHKT for why this is an interface.

Extends ​

  • PgDeleteHKTBase

Properties ​

PropertyTypeOverridesInherited fromDefined in
_typePgUnthrownDeleteBase<PgTable<TableConfig>, PgQueryResultHKT, ColumnsSelection | undefined, Record<string, unknown> | undefined, boolean, string>PgDeleteHKTBase._type-packages/drizzle/src/pg-core/delete.ts:38
dynamicboolean-PgDeleteHKTBase.dynamicnode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/delete.d.ts:33
excludedMethodsstring-PgDeleteHKTBase.excludedMethodsnode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/delete.d.ts:34
queryResultunknown-PgDeleteHKTBase.queryResultnode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/delete.d.ts:30
returningunknown-PgDeleteHKTBase.returningnode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/delete.d.ts:32
selectedFieldsunknown-PgDeleteHKTBase.selectedFieldsnode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/delete.d.ts:31
tableunknown-PgDeleteHKTBase.tablenode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/delete.d.ts:29

PgUnthrownInsertHKT ​

Defined in: packages/drizzle/src/pg-core/insert.ts:36

The higher-kinded type that keeps every chained insert method returning an unthrown builder rather than drizzle's own.

Remarks ​

See PgUnthrownSelectHKT for why this is an interface.

Extends ​

  • PgInsertHKTBase

Properties ​

PropertyTypeOverridesInherited fromDefined in
_typePgUnthrownInsertBase<PgTable<TableConfig>, PgQueryResultHKT, unknown, unknown, boolean, string>PgInsertHKTBase._type-packages/drizzle/src/pg-core/insert.ts:37
dynamicboolean-PgInsertHKTBase.dynamicnode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/insert.d.ts:70
excludedMethodsstring-PgInsertHKTBase.excludedMethodsnode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/insert.d.ts:71
queryResultunknown-PgInsertHKTBase.queryResultnode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/insert.d.ts:67
resultunknown-PgInsertHKTBase.resultnode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/insert.d.ts:72
returningunknown-PgInsertHKTBase.returningnode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/insert.d.ts:69
selectedFieldsunknown-PgInsertHKTBase.selectedFieldsnode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/insert.d.ts:68
tableunknown-PgInsertHKTBase.tablenode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/insert.d.ts:66

PgUnthrownRelationalQueryHKT ​

Defined in: packages/drizzle/src/pg-core/query.ts:22

The higher-kinded type that makes db.query.<table>.findMany() build an unthrown relational query rather than drizzle's own.

Remarks ​

See PgUnthrownSelectHKT for why this is an interface.

Extends ​

  • PgRelationalQueryHKTBase

Properties ​

PropertyTypeOverridesInherited fromDefined in
_typePgUnthrownRelationalQuery<unknown>PgRelationalQueryHKTBase._type-packages/drizzle/src/pg-core/query.ts:23
resultunknown-PgRelationalQueryHKTBase.resultnode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/query.d.ts:27

PgUnthrownSelectHKT ​

Defined in: packages/drizzle/src/pg-core/select.ts:42

The higher-kinded type that keeps every chained select method returning an unthrown builder rather than drizzle's own.

Remarks ​

Drizzle's base builders are container-agnostic: .where(), .limit() and the joins all rebuild this through PgSelectKind<THKT, …>, and the tree the query stays in is decided by this one type. It must be an interface — the pattern reads this["tableName"] and the polymorphic this type only exists inside an interface or class declaration.

Extends ​

  • PgSelectHKTBase

Type Parameters ​

Type ParameterDefault typeDescription
TErrorneverthe select's modeled error channel, carried through every chained method — see PgUnthrownSelectBase.

Properties ​

PropertyTypeOverridesInherited fromDefined in
_typePgUnthrownSelectBase<string | undefined, ColumnsSelection, SelectMode, Record<string, JoinNullability>, boolean, string, unknown[], ColumnsSelection, TError>PgSelectHKTBase._type-packages/drizzle/src/pg-core/select.ts:43
dynamicboolean-PgSelectHKTBase.dynamicnode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.types.d.ts:95
excludedMethodsstring-PgSelectHKTBase.excludedMethodsnode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.types.d.ts:96
nullabilityMapunknown-PgSelectHKTBase.nullabilityMapnode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.types.d.ts:94
resultunknown-PgSelectHKTBase.resultnode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.types.d.ts:97
selectedFieldsunknown-PgSelectHKTBase.selectedFieldsnode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.types.d.ts:98
selectionunknown-PgSelectHKTBase.selectionnode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.types.d.ts:92
selectModeSelectMode-PgSelectHKTBase.selectModenode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.types.d.ts:93
tableNamestring | undefined-PgSelectHKTBase.tableNamenode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/select.types.d.ts:91

PgUnthrownUpdateHKT ​

Defined in: packages/drizzle/src/pg-core/update.ts:41

The higher-kinded type that keeps every chained update method returning an unthrown builder rather than drizzle's own.

Remarks ​

See PgUnthrownSelectHKT for why this is an interface.

Extends ​

  • PgUpdateHKTBase

Properties ​

PropertyTypeOverridesInherited fromDefined in
_typePgUnthrownUpdateBase<PgTable<TableConfig>, PgQueryResultHKT, | PgTable<TableConfig> | PgViewBase<ViewConfig<ColumnsSelection>> | SQL<unknown> | Subquery<string, Record<string, unknown>> | undefined, ColumnsSelection | undefined, Record<string, unknown> | undefined, Record<string, JoinNullability>, Join[], boolean, string>PgUpdateHKTBase._type-packages/drizzle/src/pg-core/update.ts:42
dynamicboolean-PgUpdateHKTBase.dynamicnode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/update.d.ts:76
excludedMethodsstring-PgUpdateHKTBase.excludedMethodsnode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/update.d.ts:77
fromunknown-PgUpdateHKTBase.fromnode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/update.d.ts:73
joinsunknown-PgUpdateHKTBase.joinsnode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/update.d.ts:70
nullabilityMapunknown-PgUpdateHKTBase.nullabilityMapnode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/update.d.ts:71
queryResultunknown-PgUpdateHKTBase.queryResultnode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/update.d.ts:72
returningunknown-PgUpdateHKTBase.returningnode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/update.d.ts:75
selectedFieldsunknown-PgUpdateHKTBase.selectedFieldsnode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/update.d.ts:74
tableunknown-PgUpdateHKTBase.tablenode_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/query-builders/update.d.ts:69

PgUnthrownSelectBuilder ​

ts
type PgUnthrownSelectBuilder<TSelection, TError> = PgSelectBuilder<TSelection, PgUnthrownSelectHKT<TError>>;

Defined in: packages/drizzle/src/pg-core/select.ts:65

The builder db.select() returns, before a table has been chosen.

Type Parameters ​

Type ParameterDefault typeDescription
TSelection extends SelectedFields | undefined--
TErrorneverthe select's modeled error channel: never for a read, PgQueryError for a select whose WITH list may write — see PgUnthrownSelectBase.

PgUnthrownSelectPreparedQuery ​

ts
type PgUnthrownSelectPreparedQuery<T, TError> = [TError] extends [never] ? PgUnthrownSafePreparedQuery<T> : PgUnthrownPreparedQuery<T>;

Defined in: packages/drizzle/src/pg-core/select.ts:97

The prepared statement a select hands back: the defect-only one for a read, the qualified one for a select whose WITH list may write.

Type Parameters ​

Type Parameter
T extends PreparedQueryConfig
TError

ResultThen ​

ts
type ResultThen<T, E> = <TResult1, TResult2>(onFulfilled?, onRejected?) => PromiseLike<TResult1 | TResult2>;

Defined in: packages/drizzle/src/pg-core/awaitable.ts:54

The then that makes a query builder awaitable, resolving to a Result.

Type Parameters ​

Type ParameterDefault typeDescription
T-the value the query succeeds with; the awaited type is Result<T, E>.
EPgQueryErrorthe query's modeled error channel. Defaults to PgQueryError, which is what a write carries; the four read builders pass never, because a read has no modeled failure at all — see runSafeQuery.

Type Parameters ​

Type ParameterDefault type
TResult1Result<T, E>
TResult2never

Parameters ​

ParameterType
onFulfilled?((value) => TResult1 | PromiseLike<TResult1>) | null
onRejected?((reason) => TResult2 | PromiseLike<TResult2>) | null

Returns ​

PromiseLike<TResult1 | TResult2>

Remarks ​

Drizzle's promise and Effect trees each make their builders runnable the same way: the builder carries a then that defers to execute(). The promise tree gets it from the QueryPromise mixin, whose then is literally this.execute().then(onFulfilled, onRejected).

This package cannot reuse that mixin. QueryPromise<T> declares execute(): Promise<T>, and ours returns an AsyncResult<T, PgQueryError> — so merging its type would contradict the very method it delegates to. (Its applyMixins helper is @internal and absent from drizzle's published .d.ts besides.) Each builder therefore declares this then itself, built by resultThen, with the awaited type it actually produces.

Awaiting a builder yields a Result, never a rejection: execute() returns an AsyncResult, whose internal promise never rejects, and the compilation step ahead of it runs inside the same boundary — see runQuery. catch and finally are deliberately not offered: there is no rejection for them to observe. onRejected is still forwarded, exactly as AsyncResult.then forwards it, so a hypothetical internal rejection settles the await instead of hanging it.

Database ​

PgUnthrownDatabase ​

Defined in: packages/drizzle/src/pg-core/db.ts:136

A Postgres database whose every query resolves to an AsyncResult.

Remarks ​

The unthrown sibling of drizzle's own PgAsyncDatabase (promises) and PgEffectDatabase (Effects). The entry points below only build queries — every one of them hands back a builder from this package's tree, and nothing touches the database until that builder is awaited or executed. That is why their bodies are drizzle's, unchanged but for the builder classes.

Extended by ​

Type Parameters ​

Type ParameterDefault typeDescription
TQueryResult extends PgQueryResultHKT-the driver's result kind, which decides what a write without .returning() resolves to.
TRelations extends AnyRelationsEmptyRelationsthe relational schema backing query.

Constructors ​

Constructor ​
ts
new PgUnthrownDatabase<TQueryResult, TRelations>(
   dialect, 
   session, 
   relations, 
   parseRqbJson?, 
   tagged?
): PgUnthrownDatabase<TQueryResult, TRelations>;

Defined in: packages/drizzle/src/pg-core/db.ts:159

Parameters ​
ParameterTypeDefault valueDescription
dialectPgDialectundefined-
sessionPgUnthrownSession<unknown>undefined-
relationsTRelationsundefined-
parseRqbJson?booleanfalse-
tagged?booleanfalse-
Returns ​

PgUnthrownDatabase<TQueryResult, TRelations>

Properties ​

PropertyModifierTypeDefault valueDescriptionDefined in
_readonlyobjectundefined-packages/drizzle/src/pg-core/db.ts:142
_.relationsreadonlyTRelationsundefined-packages/drizzle/src/pg-core/db.ts:143
_.sessionreadonlyPgUnthrownSession<unknown>undefined-packages/drizzle/src/pg-core/db.ts:144
$withreadonlyPgUnthrownWithBuilder...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 rows = (await db.with(sq).select().from(sq)).get(); 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 rows = (await db.with(sq).select({ name: sq.name }).from(sq)).get();packages/drizzle/src/pg-core/db.ts:254
queryreadonly{ [K in string | number | symbol]: RelationalQueryBuilder<TRelations, TRelations[K], PgUnthrownRelationalQueryHKT> }undefinedThe relational query API — db.query.users.findMany(…), one entry per table in the relational schema.packages/drizzle/src/pg-core/db.ts:151
taggedreadonlybooleanfalse-packages/drizzle/src/pg-core/db.ts:166
[entityKind]static readonlystring"PgUnthrownDatabase"-packages/drizzle/src/pg-core/db.ts:140

Methods ​

$count() ​
ts
$count(source, filters?): PgUnthrownCountBuilder;

Defined in: packages/drizzle/src/pg-core/db.ts:308

Count the rows a table, view or subquery yields, optionally filtered.

Parameters ​
ParameterType
source| PgTable<TableConfig> | PgViewBase<ViewConfig<ColumnsSelection>> | SQL<unknown> | SQLWrapper<unknown>
filters?SQL<unknown>
Returns ​

PgUnthrownCountBuilder

Example ​
ts
const total = (await db.$count(users, eq(users.active, true))).get();
//    ^? number — a count is a read, so its error channel is `never`.
delete() ​
ts
delete<TTable>(table): PgUnthrownDeleteBase<TTable, TQueryResult>;

Defined in: packages/drizzle/src/pg-core/db.ts:715

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

A write carries the full PgQueryError union — a delete can still raise 23505 through an ON DELETE SET DEFAULT — so awaiting the builder resolves to a Result you fold with mapErrCases or match.

Type Parameters ​
Type Parameter
TTable extends PgTable<TableConfig>
Parameters ​
ParameterTypeDescription
tableTTableThe table to delete from.
Returns ​

PgUnthrownDeleteBase<TTable, TQueryResult>

Example ​
ts
// Delete all rows in the 'cars' table
const all = await db.delete(cars);
//    ^? Result<DeleteResult<…>, PgQueryError>

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

// Delete with returning clause
const deleted = await db.delete(cars).where(eq(cars.id, 1)).returning();
execute() ​
ts
execute<TRow>(query): PgUnthrownRaw<PgQueryResultKind<TQueryResult, TRow>>;

Defined in: packages/drizzle/src/pg-core/db.ts:752

Run a statement drizzle does not model — a raw SQL fragment or a string.

Type Parameters ​
Type ParameterDefault type
TRow extends Record<string, unknown>Record<string, unknown>
Parameters ​
ParameterType
querystring | SQLWrapper<unknown>
Returns ​

PgUnthrownRaw<PgQueryResultKind<TQueryResult, TRow>>

Remarks ​

Unlike every other entry point, this one compiles its argument eagerly, because PgUnthrownRaw is defined as holding an already-prepared query (that is what makes its getSQL, getQuery and _prepare synchronous accessors, exactly as in drizzle). Compilation therefore happens here rather than at await, and a SQLWrapper that cannot compile throws at this call site instead of yielding a defect.

That is a deliberate line, not an oversight: the contract this package makes is about running a query — awaiting a builder, or calling its execute() — and db.execute(…) is the factory that produces one, not the run itself. The builder it returns is fully guarded. Reaching the throw takes handing in a query builder that is already broken (db.execute(db.select({ t: other.col }).from(users))); a string or a sql template — the documented use — cannot. Closing the gap would mean deferring compilation, which would cost PgRaw's shape and its synchronous accessors for a case where the argument, not the statement, is the bug.

Example ​
ts
const result = await db.execute(sql`select now()`);
insert() ​
ts
insert<TTable>(table): PgInsertBuilder<TTable, TQueryResult, "all", false, PgUnthrownInsertHKT>;

Defined in: packages/drizzle/src/pg-core/db.ts:673

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

A write carries the full PgQueryError union, so awaiting the builder resolves to a Result you fold with mapErrCases or match — never a rejection.

Type Parameters ​
Type Parameter
TTable extends PgTable<TableConfig>
Parameters ​
ParameterTypeDescription
tableTTableThe table to insert into.
Returns ​

PgInsertBuilder<TTable, TQueryResult, "all", false, PgUnthrownInsertHKT>

Example ​
ts
// Insert one row
const one = await db.insert(cars).values({ brand: "BMW" });
//    ^? Result<InsertResult<…>, PgQueryError>

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

// Insert with returning clause
const inserted = await db.insert(cars).values({ brand: "BMW" }).returning();
refreshMaterializedView() ​
ts
refreshMaterializedView<TView>(view): PgUnthrownRefreshMaterializedView<TQueryResult>;

Defined in: packages/drizzle/src/pg-core/db.ts:720

Rebuild a materialized view's stored rows.

Type Parameters ​
Type Parameter
TView extends PgMaterializedView<ViewConfig<ColumnsSelection>>
Parameters ​
ParameterType
viewTView
Returns ​

PgUnthrownRefreshMaterializedView<TQueryResult>

select() ​
Call Signature ​
ts
select(): PgUnthrownSelectBuilder<undefined>;

Defined in: packages/drizzle/src/pg-core/db.ts:497

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

Awaiting the builder resolves to a Result, never rows directly — a read has no modeled failure, so the error channel is never and .get() compiles.

Returns ​

PgUnthrownSelectBuilder<undefined>

Example ​
ts
// Select all columns and all rows from the 'cars' table
const allCars = (await db.select().from(cars)).get();

// Select specific columns and all rows from the 'cars' table
const carsIdsAndBrands = (
  await db
    .select({
      id: cars.id,
      brand: cars.brand,
    })
    .from(cars)
).get();
Call Signature ​
ts
select<TSelection>(fields): PgUnthrownSelectBuilder<TSelection>;

Defined in: packages/drizzle/src/pg-core/db.ts:498

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

Awaiting the builder resolves to a Result, never rows directly — a read has no modeled failure, so the error channel is never and .get() compiles.

Type Parameters ​
Type Parameter
TSelection extends SelectedFields
Parameters ​
ParameterType
fieldsTSelection
Returns ​

PgUnthrownSelectBuilder<TSelection>

Example ​
ts
// Select all columns and all rows from the 'cars' table
const allCars = (await db.select().from(cars)).get();

// Select specific columns and all rows from the 'cars' table
const carsIdsAndBrands = (
  await db
    .select({
      id: cars.id,
      brand: cars.brand,
    })
    .from(cars)
).get();
selectDistinct() ​
Call Signature ​
ts
selectDistinct(): PgUnthrownSelectBuilder<undefined>;

Defined in: packages/drizzle/src/pg-core/db.ts:538

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. Pass a selection object to specify the columns you want to select.

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

Returns ​

PgUnthrownSelectBuilder<undefined>

Example ​
ts
// Select all unique rows from the 'cars' table
const unique = (
  await db.selectDistinct().from(cars).orderBy(cars.id, cars.brand, cars.color)
).get();

// Select all unique brands from the 'cars' table
const brands = (
  await db.selectDistinct({ brand: cars.brand }).from(cars).orderBy(cars.brand)
).get();
Call Signature ​
ts
selectDistinct<TSelection>(fields): PgUnthrownSelectBuilder<TSelection>;

Defined in: packages/drizzle/src/pg-core/db.ts:539

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. Pass a selection object to specify the columns you want to select.

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

Type Parameters ​
Type Parameter
TSelection extends SelectedFields
Parameters ​
ParameterType
fieldsTSelection
Returns ​

PgUnthrownSelectBuilder<TSelection>

Example ​
ts
// Select all unique rows from the 'cars' table
const unique = (
  await db.selectDistinct().from(cars).orderBy(cars.id, cars.brand, cars.color)
).get();

// Select all unique brands from the 'cars' table
const brands = (
  await db.selectDistinct({ brand: cars.brand }).from(cars).orderBy(cars.brand)
).get();
selectDistinctOn() ​
Call Signature ​
ts
selectDistinctOn(on): PgUnthrownSelectBuilder<undefined>;

Defined in: packages/drizzle/src/pg-core/db.ts:584

Adds distinct on expression to the select query.

Calling this method will specify how the unique rows are determined.

Use .from() method to specify which table to select from. Pass a selection object as the second argument to specify the columns you want to select.

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

Parameters ​
ParameterTypeDescription
on( | SQLWrapper<unknown> | PgColumn<any, PgColumnBaseConfig<any>, { }>)[]The expression defining uniqueness.
Returns ​

PgUnthrownSelectBuilder<undefined>

Example ​
ts
// Select the first row for each unique brand from the 'cars' table
const firstPerBrand = (
  await db.selectDistinctOn([cars.brand]).from(cars).orderBy(cars.brand)
).get();

// The first occurrence of each unique brand, with its color
const brandColors = (
  await db
    .selectDistinctOn([cars.brand], { brand: cars.brand, color: cars.color })
    .from(cars)
    .orderBy(cars.brand, cars.color)
).get();
Call Signature ​
ts
selectDistinctOn<TSelection>(on, fields): PgUnthrownSelectBuilder<TSelection>;

Defined in: packages/drizzle/src/pg-core/db.ts:585

Adds distinct on expression to the select query.

Calling this method will specify how the unique rows are determined.

Use .from() method to specify which table to select from. Pass a selection object as the second argument to specify the columns you want to select.

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

Type Parameters ​
Type Parameter
TSelection extends SelectedFields
Parameters ​
ParameterTypeDescription
on( | SQLWrapper<unknown> | PgColumn<any, PgColumnBaseConfig<any>, { }>)[]The expression defining uniqueness.
fieldsTSelection-
Returns ​

PgUnthrownSelectBuilder<TSelection>

Example ​
ts
// Select the first row for each unique brand from the 'cars' table
const firstPerBrand = (
  await db.selectDistinctOn([cars.brand]).from(cars).orderBy(cars.brand)
).get();

// The first occurrence of each unique brand, with its color
const brandColors = (
  await db
    .selectDistinctOn([cars.brand], { brand: cars.brand, color: cars.color })
    .from(cars)
    .orderBy(cars.brand, cars.color)
).get();
update() ​
ts
update<TTable>(table): PgUpdateBuilder<TTable, TQueryResult, PgUnthrownUpdateHKT>;

Defined in: packages/drizzle/src/pg-core/db.ts:639

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

A write carries the full PgQueryError union, so awaiting the builder resolves to a Result you fold with mapErrCases or match — never a rejection.

Type Parameters ​
Type Parameter
TTable extends PgTable<TableConfig>
Parameters ​
ParameterTypeDescription
tableTTableThe table to update.
Returns ​

PgUpdateBuilder<TTable, TQueryResult, PgUnthrownUpdateHKT>

Example ​
ts
// Update all rows in the 'cars' table
const all = await db.update(cars).set({ color: "red" });
//    ^? Result<UpdateResult<…>, PgQueryError>

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

// Update with returning clause
const updated = await db
  .update(cars)
  .set({ color: "red" })
  .where(eq(cars.id, 1))
  .returning();
with() ​
ts
with<Q>(...queries): object;

Defined in: packages/drizzle/src/pg-core/db.ts:341

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

Type Parameters ​
Type Parameter
Q extends WithSubquery<string, Record<string, unknown>>[]
Parameters ​
ParameterTypeDescription
...queriesQThe CTEs to incorporate into the main query.
Returns ​

object

NameTypeDefined in
delete()<TTable>(table) => PgUnthrownDeleteBase<TTable, TQueryResult>packages/drizzle/src/pg-core/db.ts:369
insert()<TTable>(table) => PgInsertBuilder<TTable, TQueryResult, "all", false, PgUnthrownInsertHKT>packages/drizzle/src/pg-core/db.ts:366
select(){ (): PgUnthrownSelectBuilder<undefined, WithListError<Q[number]>>; <TSelection>(fields): PgUnthrownSelectBuilder<TSelection, WithListError<Q[number]>>; }packages/drizzle/src/pg-core/db.ts:344
selectDistinct(){ (): PgUnthrownSelectBuilder<undefined, WithListError<Q[number]>>; <TSelection>(fields): PgUnthrownSelectBuilder<TSelection, WithListError<Q[number]>>; }packages/drizzle/src/pg-core/db.ts:350
selectDistinctOn(){ (on): PgUnthrownSelectBuilder<undefined, WithListError<Q[number]>>; <TSelection>(on, fields): PgUnthrownSelectBuilder<TSelection, WithListError<Q[number]>>; }packages/drizzle/src/pg-core/db.ts:356
update()<TTable>(table) => PgUpdateBuilder<TTable, TQueryResult, PgUnthrownUpdateHKT>packages/drizzle/src/pg-core/db.ts:363
Example ​
ts
// 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 rows = (await db.with(sq).select().from(sq)).get();

CteError ​

ts
type CteError<TError> = object;

Defined in: packages/drizzle/src/pg-core/db.ts:59

The modeled error channel a CTE contributes to the select that uses it — never for a CTE that only reads, PgQueryError for one that may write.

Remarks ​

A phantom in drizzle's own _ type bag, where drizzle keeps its other compile-time-only fields; nothing sets it at runtime, which is why it is optional. The runtime half of the same decision is readOnlyCtes.

Type Parameters ​

Type Parameter
TError

Properties ​

PropertyModifierTypeDefined in
_readonlyobjectpackages/drizzle/src/pg-core/db.ts:59
_.unthrownError?readonlyTErrorpackages/drizzle/src/pg-core/db.ts:59

WithListError ​

ts
type WithListError<W> = W extends object ? unknown extends E ? PgQueryError : E : PgQueryError;

Defined in: packages/drizzle/src/pg-core/db.ts:79

The error channel a WITH list adds to its select: the union of what its CTEs may raise. A CTE this package did not build (a stock drizzle $with) carries no CteError and is assumed to write — nothing says it cannot.

Type Parameters ​

Type Parameter
W

Other ​

CheckViolation ​

Defined in: packages/drizzle/src/errors.ts:59

A check constraint was violated (SQLSTATE 23514).

Extends ​

  • TaggedErrorInstance<"CheckViolation", ConstraintFields>

Constructors ​

Constructor ​
ts
new CheckViolation(fields): CheckViolation;

Defined in: packages/drizzle/src/errors.ts:62

Parameters ​
ParameterType
fieldsConstraintFields
Returns ​

CheckViolation

Overrides ​

TaggedError("CheckViolation")<ConstraintFields>.constructor

Properties ​

PropertyModifierTypeDefault valueOverridesInherited fromDefined in
_tagreadonly"CheckViolation"undefined-TaggedError("CheckViolation")._tagpackages/core/dist/index.d.mts:2363
causepublicunknownundefined-TaggedError("CheckViolation").causenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2022.error.d.ts:24
constraintreadonlystring | undefinedundefined-TaggedError("CheckViolation").constraintpackages/drizzle/src/errors.ts:11
detailreadonlystring | undefinedundefined-TaggedError("CheckViolation").detailpackages/drizzle/src/errors.ts:13
messagepublicstring"check constraint violated"TaggedError("CheckViolation").message-packages/drizzle/src/errors.ts:60
namepublicstringundefined-TaggedError("CheckViolation").namenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1074
stack?publicstringundefined-TaggedError("CheckViolation").stacknode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1076
tablereadonlystring | undefinedundefined-TaggedError("CheckViolation").tablepackages/drizzle/src/errors.ts:12

ExclusionViolation ​

Defined in: packages/drizzle/src/errors.ts:69

An exclusion constraint was violated (SQLSTATE 23P01).

Extends ​

  • TaggedErrorInstance<"ExclusionViolation", ConstraintFields>

Constructors ​

Constructor ​
ts
new ExclusionViolation(fields): ExclusionViolation;

Defined in: packages/drizzle/src/errors.ts:72

Parameters ​
ParameterType
fieldsConstraintFields
Returns ​

ExclusionViolation

Overrides ​

TaggedError("ExclusionViolation")<ConstraintFields>.constructor

Properties ​

PropertyModifierTypeDefault valueOverridesInherited fromDefined in
_tagreadonly"ExclusionViolation"undefined-TaggedError("ExclusionViolation")._tagpackages/core/dist/index.d.mts:2363
causepublicunknownundefined-TaggedError("ExclusionViolation").causenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2022.error.d.ts:24
constraintreadonlystring | undefinedundefined-TaggedError("ExclusionViolation").constraintpackages/drizzle/src/errors.ts:11
detailreadonlystring | undefinedundefined-TaggedError("ExclusionViolation").detailpackages/drizzle/src/errors.ts:13
messagepublicstring"exclusion constraint violated"TaggedError("ExclusionViolation").message-packages/drizzle/src/errors.ts:70
namepublicstringundefined-TaggedError("ExclusionViolation").namenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1074
stack?publicstringundefined-TaggedError("ExclusionViolation").stacknode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1076
tablereadonlystring | undefinedundefined-TaggedError("ExclusionViolation").tablepackages/drizzle/src/errors.ts:12

ForeignKeyViolation ​

Defined in: packages/drizzle/src/errors.ts:49

A foreign key constraint was violated (SQLSTATE 23503).

Extends ​

  • TaggedErrorInstance<"ForeignKeyViolation", ConstraintFields>

Constructors ​

Constructor ​
ts
new ForeignKeyViolation(fields): ForeignKeyViolation;

Defined in: packages/drizzle/src/errors.ts:52

Parameters ​
ParameterType
fieldsConstraintFields
Returns ​

ForeignKeyViolation

Overrides ​

TaggedError("ForeignKeyViolation")<ConstraintFields>.constructor

Properties ​

PropertyModifierTypeDefault valueOverridesInherited fromDefined in
_tagreadonly"ForeignKeyViolation"undefined-TaggedError("ForeignKeyViolation")._tagpackages/core/dist/index.d.mts:2363
causepublicunknownundefined-TaggedError("ForeignKeyViolation").causenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2022.error.d.ts:24
constraintreadonlystring | undefinedundefined-TaggedError("ForeignKeyViolation").constraintpackages/drizzle/src/errors.ts:11
detailreadonlystring | undefinedundefined-TaggedError("ForeignKeyViolation").detailpackages/drizzle/src/errors.ts:13
messagepublicstring"foreign key constraint violated"TaggedError("ForeignKeyViolation").message-packages/drizzle/src/errors.ts:50
namepublicstringundefined-TaggedError("ForeignKeyViolation").namenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1074
stack?publicstringundefined-TaggedError("ForeignKeyViolation").stacknode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1076
tablereadonlystring | undefinedundefined-TaggedError("ForeignKeyViolation").tablepackages/drizzle/src/errors.ts:12

NotNullViolation ​

Defined in: packages/drizzle/src/errors.ts:94

A NOT NULL constraint was violated (SQLSTATE 23502).

Remarks ​

Carries column rather than constraint: 23502 names the offending column and has no constraint name of its own. detail and cause are not enumerable, as on the other four.

Extends ​

  • TaggedErrorInstance<"NotNullViolation", NotNullFields>

Constructors ​

Constructor ​
ts
new NotNullViolation(fields): NotNullViolation;

Defined in: packages/drizzle/src/errors.ts:97

Parameters ​
ParameterType
fieldsNotNullFields
Returns ​

NotNullViolation

Overrides ​

TaggedError("NotNullViolation")<NotNullFields>.constructor

Properties ​

PropertyModifierTypeDefault valueOverridesInherited fromDefined in
_tagreadonly"NotNullViolation"undefined-TaggedError("NotNullViolation")._tagpackages/core/dist/index.d.mts:2363
causepublicunknownundefined-TaggedError("NotNullViolation").causenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2022.error.d.ts:24
columnreadonlystring | undefinedundefined-TaggedError("NotNullViolation").columnpackages/drizzle/src/errors.ts:80
detailreadonlystring | undefinedundefined-TaggedError("NotNullViolation").detailpackages/drizzle/src/errors.ts:82
messagepublicstring"not-null constraint violated"TaggedError("NotNullViolation").message-packages/drizzle/src/errors.ts:95
namepublicstringundefined-TaggedError("NotNullViolation").namenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1074
stack?publicstringundefined-TaggedError("NotNullViolation").stacknode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1076
tablereadonlystring | undefinedundefined-TaggedError("NotNullViolation").tablepackages/drizzle/src/errors.ts:81

UniqueConstraintViolation ​

Defined in: packages/drizzle/src/errors.ts:37

A unique constraint was violated (SQLSTATE 23505).

Extends ​

  • TaggedErrorInstance<"UniqueConstraintViolation", ConstraintFields>

Constructors ​

Constructor ​
ts
new UniqueConstraintViolation(fields): UniqueConstraintViolation;

Defined in: packages/drizzle/src/errors.ts:42

Parameters ​
ParameterType
fieldsConstraintFields
Returns ​

UniqueConstraintViolation

Overrides ​

TaggedError( "UniqueConstraintViolation", )<ConstraintFields>.constructor

Properties ​

PropertyModifierTypeDefault valueOverridesInherited fromDefined in
_tagreadonly"UniqueConstraintViolation"undefined-TaggedError( "UniqueConstraintViolation", )._tagpackages/core/dist/index.d.mts:2363
causepublicunknownundefined-TaggedError( "UniqueConstraintViolation", ).causenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2022.error.d.ts:24
constraintreadonlystring | undefinedundefined-TaggedError( "UniqueConstraintViolation", ).constraintpackages/drizzle/src/errors.ts:11
detailreadonlystring | undefinedundefined-TaggedError( "UniqueConstraintViolation", ).detailpackages/drizzle/src/errors.ts:13
messagepublicstring"unique constraint violated"TaggedError( "UniqueConstraintViolation", ).message-packages/drizzle/src/errors.ts:40
namepublicstringundefined-TaggedError( "UniqueConstraintViolation", ).namenode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1074
stack?publicstringundefined-TaggedError( "UniqueConstraintViolation", ).stacknode_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1076
tablereadonlystring | undefinedundefined-TaggedError( "UniqueConstraintViolation", ).tablepackages/drizzle/src/errors.ts:12

DeleteResult ​

ts
type DeleteResult<TQueryResult, TReturning> = TReturning extends undefined ? PgQueryResultKind<TQueryResult, never> : TReturning[];

Defined in: packages/drizzle/src/pg-core/delete.ts:22

What a delete resolves to: the driver's own result object, or the returned rows once .returning() has been called.

Type Parameters ​

Type Parameter
TQueryResult extends PgQueryResultHKT
TReturning

InsertResult ​

ts
type InsertResult<TQueryResult, TReturning> = TReturning extends undefined ? PgQueryResultKind<TQueryResult, never> : TReturning[];

Defined in: packages/drizzle/src/pg-core/insert.ts:21

What an insert resolves to: the driver's own result object, or the returned rows once .returning() has been called.

Type Parameters ​

Type Parameter
TQueryResult extends PgQueryResultHKT
TReturning

PgQueryError ​

ts
type PgQueryError = 
  | UniqueConstraintViolation
  | ForeignKeyViolation
  | NotNullViolation
  | CheckViolation
  | ExclusionViolation;

Defined in: packages/drizzle/src/errors.ts:110

The full union of domain errors a Postgres query can surface.

Remarks ​

Infrastructure failures are deliberately absent — they are defects, not values. See qualifyPgError.


UpdateResult ​

ts
type UpdateResult<TQueryResult, TReturning> = TReturning extends undefined ? PgQueryResultKind<TQueryResult, never> : TReturning[];

Defined in: packages/drizzle/src/pg-core/update.ts:26

What an update resolves to: the driver's own result object, or the returned rows once .returning() has been called.

Type Parameters ​

Type Parameter
TQueryResult extends PgQueryResultHKT
TReturning

qualifyPgError() ​

ts
function qualifyPgError<D>(cause, defect): D | PgQueryError;

Defined in: packages/drizzle/src/errors.ts:165

Triage a Postgres driver failure into the modeled error channel or the defect channel — a qualify in the Thesis-#3 sense, so it drops straight into a fromPromise at a boundary of your own.

Type Parameters ​

Type Parameter
D

Parameters ​

ParameterTypeDescription
causeunknownthe rejected value from a Postgres query (a node-postgres DatabaseError, a DrizzleQueryError wrapping one, or anything else).
defect(cause) => Dthe defect helper the boundary injects (never import it).

Returns ​

D | PgQueryError

Remarks ​

Only the five 23xxx integrity-constraint codes are modeled: they are what a request handler branches on. Everything else — serialization failure (40001), deadlock (40P01), statement timeout (57014), connection loss, syntax errors — is a defect. Retry belongs in one recoverDefect wrapper that inspects the cause, not an arm at every write call site.

Only an error the server reported is triaged — one carrying a severity as well as a SQLSTATE code. Anything else with a code is a defect.

Example ​

ts
const rows = fromPromise(pool.query("select 1"), qualifyPgError);

Session ​

PgUnthrownPreparedQuery ​

Defined in: packages/drizzle/src/pg-core/session.ts:59

A prepared query whose execution yields an AsyncResult.

Remarks ​

This is the single place in the package where a driver rejection is triaged. Everything above it — the builder tree, the database facade — is type plumbing; the container swap happens here, and only here, because drizzle declares PgBasePreparedQuery.execute() as returning unknown.

Every failure leaves execute as either a modeled PgQueryError or a defect, so the returned AsyncResult's internal promise never rejects and awaiting it never throws.

Extends ​

  • PgBasePreparedQuery

Extended by ​

Type Parameters ​

Type ParameterDefault typeDescription
T extends PreparedQueryConfigPreparedQueryConfigdrizzle's per-query config, whose execute member is the value the query resolves to.

Constructors ​

Constructor ​
ts
new PgUnthrownPreparedQuery<T>(
   executor, 
   query, 
   mapper, 
   mode, 
   logger
): PgUnthrownPreparedQuery<T>;

Defined in: packages/drizzle/src/pg-core/session.ts:73

Parameters ​
ParameterTypeDescription
executor(params) => Promise<unknown>runs the query against the driver with the given bound parameters. Its rejection is what execute triages.
queryQuerythe compiled SQL and its parameter list.
mapperPgRowMapper | undefinedmaps the driver's rows to the query's declared result, or undefined to pass the driver's value through untouched.
modePgQueryModethe row shape the driver was asked for.
loggerLoggerdrizzle's query logger.
Returns ​

PgUnthrownPreparedQuery<T>

Overrides ​

PgBasePreparedQuery.constructor

Properties ​

PropertyModifierTypeDefault valueDescriptionOverridesDefined in
modereadonlyPgQueryModeundefinedthe row shape the driver was asked for.-packages/drizzle/src/pg-core/session.ts:77
[entityKind]static readonlystring"PgUnthrownPreparedQuery"-PgBasePreparedQuery.[entityKind]packages/drizzle/src/pg-core/session.ts:62

Methods ​

execute() ​
ts
execute(placeholderValues?): AsyncResult<T["execute"], PgQueryError>;

Defined in: packages/drizzle/src/pg-core/session.ts:142

Run the query, triaging any driver failure into the error or defect channel.

Parameters ​
ParameterTypeDescription
placeholderValues?Record<string, unknown>values for the query's named placeholders.
Returns ​

AsyncResult<T["execute"], PgQueryError>

Remarks ​

The promise is started from a thunk so that a synchronous throw — a missing placeholder value, a driver that validates its arguments eagerly — is caught by the same boundary as a rejection. execute therefore neither throws nor rejects: awaiting it always yields a Result.

Overrides ​

PgBasePreparedQuery.execute

getQuery() ​
ts
getQuery(): Query;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/session.d.ts:14

Returns ​

Query

Inherited from ​

PgBasePreparedQuery.getQuery


PgUnthrownSafePreparedQuery ​

Defined in: packages/drizzle/src/pg-core/session.ts:201

A prepared query whose every failure is a defect — the read builders' half of PgUnthrownPreparedQuery.

Remarks ​

A read has no modeled failure (see runSafeQuery), so the four read builders declare E = never. Their prepare(name) returns one of these, so running a prepared read reaches the same fromSafePromise boundary that execute() and await do — all three routes agree, and none of them can put a value in a channel the type calls empty.

This is a subclass rather than a type parameter on PgUnthrownPreparedQuery deliberately. A parameterised E would have to pick its boundary from a constructor-injected function, and the injected default (fromPromise + qualifyPgError, typed PgQueryError) is not assignable to an unresolved E — so the single-class form needs a cast exactly where the type and the runtime must not be allowed to drift apart. Overriding execute needs none: AsyncResult is covariant in E, so AsyncResult<T, never> already satisfies the base's declaration, and the narrower type is reachable only through this class, whose execute is the safe one. The weld is by construction.

Extends ​

Type Parameters ​

Type ParameterDefault typeDescription
T extends PreparedQueryConfigPreparedQueryConfigdrizzle's per-query config, whose execute member is the value the query resolves to.

Constructors ​

Constructor ​
ts
new PgUnthrownSafePreparedQuery<T>(
   executor, 
   query, 
   mapper, 
   mode, 
   logger
): PgUnthrownSafePreparedQuery<T>;

Defined in: packages/drizzle/src/pg-core/session.ts:73

Parameters ​
ParameterTypeDescription
executor(params) => Promise<unknown>runs the query against the driver with the given bound parameters. Its rejection is what execute triages.
queryQuerythe compiled SQL and its parameter list.
mapperPgRowMapper | undefinedmaps the driver's rows to the query's declared result, or undefined to pass the driver's value through untouched.
modePgQueryModethe row shape the driver was asked for.
loggerLoggerdrizzle's query logger.
Returns ​

PgUnthrownSafePreparedQuery<T>

Inherited from ​

PgUnthrownPreparedQuery.constructor

Properties ​

PropertyModifierTypeDefault valueDescriptionOverridesInherited fromDefined in
modereadonlyPgQueryModeundefinedthe row shape the driver was asked for.-PgUnthrownPreparedQuery.modepackages/drizzle/src/pg-core/session.ts:77
[entityKind]static readonlystring"PgUnthrownSafePreparedQuery"-PgUnthrownPreparedQuery.[entityKind]-packages/drizzle/src/pg-core/session.ts:204

Methods ​

execute() ​
ts
execute(placeholderValues?): AsyncResult<T["execute"], never>;

Defined in: packages/drizzle/src/pg-core/session.ts:213

Run the query. Every failure — a constraint violation raised by a volatile function the read called included — is a Defect; the error channel is never.

Parameters ​
ParameterTypeDescription
placeholderValues?Record<string, unknown>values for the query's named placeholders.
Returns ​

AsyncResult<T["execute"], never>

Overrides ​

PgUnthrownPreparedQuery.execute

getQuery() ​
ts
getQuery(): Query;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/session.d.ts:14

Returns ​

Query

Inherited from ​

PgUnthrownPreparedQuery.getQuery


abstract PgUnthrownSession ​

Defined in: packages/drizzle/src/pg-core/session.ts:237

The session every unthrown Postgres driver implements.

Remarks ​

The mirror of drizzle's own PgAsyncSession / PgEffectSession: PgSession declares execute / arrays / objects as returning unknown, which is precisely the seam that lets a fourth execution container — AsyncResult — be plugged in alongside promises and Effects.

Extends ​

  • PgSession

Extended by ​

Type Parameters ​

Type ParameterDescription
TTransactionthe transaction handle passed to a PgUnthrownSession.transaction callback. It is a parameter rather than a concrete type because the transaction class is built on top of the database facade, which in turn is built on this session; the driver that owns both supplies it.

Constructors ​

Constructor ​
ts
new PgUnthrownSession<TTransaction>(dialect): PgUnthrownSession<TTransaction>;

Defined in: node_modules/.pnpm/drizzle-orm@1.0.0-rc.5-5935859_@electric-sql+pglite@0.4.3_@types+pg@8.23.1_better-sqlit_5673ebe1f2b3df7b309939d01388aef3/node_modules/drizzle-orm/pg-core/session.d.ts:33

Parameters ​
ParameterType
dialectPgDialect
Returns ​

PgUnthrownSession<TTransaction>

Inherited from ​

PgSession.constructor

Properties ​

PropertyModifierTypeDefault valueOverridesDefined in
[entityKind]static readonlystring"PgUnthrownSession"PgSession.[entityKind]packages/drizzle/src/pg-core/session.ts:238

Methods ​

arrays() ​
ts
arrays(query): AsyncResult<unknown, PgQueryError>;

Defined in: packages/drizzle/src/pg-core/session.ts:276

Run a raw SQL fragment, returning each row as an array of column values.

Parameters ​
ParameterType
querySQL
Returns ​

AsyncResult<unknown, PgQueryError>

Overrides ​

PgSession.arrays

execute() ​
ts
execute(query): AsyncResult<unknown, PgQueryError>;

Defined in: packages/drizzle/src/pg-core/session.ts:271

Run a raw SQL fragment, returning the driver's own result object.

Parameters ​
ParameterType
querySQL
Returns ​

AsyncResult<unknown, PgQueryError>

Remarks ​

Compilation runs inside the failure boundary — see runQuery. dialect.sqlToQuery throws for mistakes that are type-legal and reachable, and a throw escaping here would land on a caller who has no try/catch, because this method's contract is a Result.

Overrides ​

PgSession.execute

objects() ​
ts
objects(query): AsyncResult<unknown, PgQueryError>;

Defined in: packages/drizzle/src/pg-core/session.ts:281

Run a raw SQL fragment, returning each row as a column-keyed object.

Parameters ​
ParameterType
querySQL
Returns ​

AsyncResult<unknown, PgQueryError>

Overrides ​

PgSession.objects

prepareQuery() ​
ts
abstract prepareQuery<T>(
   query, 
   mode, 
   name, 
   mapper?, 
   queryMetadata?, 
   cacheConfig?
): PgUnthrownPreparedQuery<T>;

Defined in: packages/drizzle/src/pg-core/session.ts:240

Type Parameters ​
Type ParameterDefault type
T extends PreparedQueryConfigPreparedQueryConfig
Parameters ​
ParameterType
queryQuery
modePgQueryMode
namestring | boolean
mapper?PgRowMapper
queryMetadata?{ tables: string[]; type: "insert" | "update" | "select" | "delete"; }
queryMetadata.tablesstring[]
queryMetadata.type"insert" | "update" | "select" | "delete"
cacheConfig?WithCacheConfig
Returns ​

PgUnthrownPreparedQuery<T>

Overrides ​

PgSession.prepareQuery

transaction() ​
ts
abstract transaction<A, E>(fn, config?): AsyncResult<A, PgQueryError | E>;

Defined in: packages/drizzle/src/pg-core/session.ts:257

Run fn inside a database transaction.

Type Parameters ​
Type Parameter
A
E
Parameters ​
ParameterType
fn(tx) => AsyncResult<A, E>
config?PgTransactionConfig
Returns ​

AsyncResult<A, PgQueryError | E>

Remarks ​

An Err from fn rolls back and re-surfaces typed; a defect rolls back and stays a defect. The transaction's own control statements can fail too, so PgQueryError joins the callback's error channel.


PgQueryMode ​

ts
type PgQueryMode = "arrays" | "objects" | "raw";

Defined in: packages/drizzle/src/pg-core/session.ts:22

The row shapes a prepared query can be asked to produce.


PgRowMapper ​

ts
type PgRowMapper = (rows) => unknown;

Defined in: packages/drizzle/src/pg-core/session.ts:39

A row mapper, as handed over by a drizzle query builder.

Parameters ​

ParameterType
rowsnever[]

Returns ​

unknown

Remarks ​

The parameter is never[] — the bottom array type — deliberately. The session never inspects rows: it forwards whatever the driver produced to the mapper the builder supplied, and each builder asks for a different row shape (unknown[][] for a column-array select, unknown[][] | Record<string, unknown>[] for a relational query). Under strictFunctionTypes a parameter is checked contravariantly, so never[] is the one parameter type every such mapper is assignable to. Spelling it any[] would accept exactly the same set while giving up type-checking inside every mapper that reads it.

Released under the MIT License.