PgwasmTransaction
Defined in: packages/pgwasm/src/drizzle/session.ts:100
Extends
Section titled “Extends”PgAsyncTransaction<PgwasmQueryResultHKT,TRelations>
Type Parameters
Section titled “Type Parameters”TRelations
Section titled “TRelations”TRelations extends AnyRelations
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new PgwasmTransaction<
TRelations>(dialect,session,relations,nestedIndex,parseRqbJson):PgwasmTransaction<TRelations>
Defined in: packages/pgwasm/src/drizzle/session.ts:108
Parameters
Section titled “Parameters”dialect
Section titled “dialect”PgDialect
session
Section titled “session”PgwasmSession<TRelations>
relations
Section titled “relations”TRelations
nestedIndex
Section titled “nestedIndex”number | undefined
parseRqbJson
Section titled “parseRqbJson”boolean | undefined
Returns
Section titled “Returns”PgwasmTransaction<TRelations>
Overrides
Section titled “Overrides”PgAsyncTransaction< PgwasmQueryResultHKT, TRelations >.constructor
Properties
Section titled “Properties”
readonly_:object
Defined in: node_modules/.bun/drizzle-orm@1.0.0-rc.4+7a682c4b82ae109f/node_modules/drizzle-orm/pg-core/async/db.d.ts:30
relations
Section titled “relations”
readonlyrelations:TRelations
session
Section titled “session”
readonlysession:PgAsyncSession<PgwasmQueryResultHKT,TRelations>
Inherited from
Section titled “Inherited from”PgAsyncTransaction._
$cache
Section titled “$cache”$cache:
object
Defined in: node_modules/.bun/drizzle-orm@1.0.0-rc.4+7a682c4b82ae109f/node_modules/drizzle-orm/pg-core/async/db.d.ts:74
invalidate
Section titled “invalidate”invalidate: (
params) =>Promise<void>
Invoked if insert, update, delete was invoked
Parameters
Section titled “Parameters”params
Section titled “params”MutationOption
Returns
Section titled “Returns”Promise<void>
Inherited from
Section titled “Inherited from”PgAsyncTransaction.$cache
$with:
WithBuilder
Defined in: node_modules/.bun/drizzle-orm@1.0.0-rc.4+7a682c4b82ae109f/node_modules/drizzle-orm/pg-core/async/db.d.ts:72
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
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
Section titled “Example”// Create a subquery with alias 'sq' and use it in the select queryconst sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
const result = await db.with(sq).select().from(sq);To select arbitrary SQL values as fields in a CTE and reference them in other CTEs or in the main query, you need to add aliases to them:
// Select an arbitrary SQL value as a field in a CTE and reference it in the main queryconst sq = db.$with('sq').as(db.select({ name: sql<string>`upper(${users.name})`.as('name'),}).from(users));
const result = await db.with(sq).select({ name: sq.name }).from(sq);Inherited from
Section titled “Inherited from”PgAsyncTransaction.$with
query: { [K in string | number | symbol]: RelationalQueryBuilder<TRelations, TRelations[K], PgAsyncRelationalQueryHKT> }
Defined in: node_modules/.bun/drizzle-orm@1.0.0-rc.4+7a682c4b82ae109f/node_modules/drizzle-orm/pg-core/async/db.d.ts:34
Inherited from
Section titled “Inherited from”PgAsyncTransaction.query
tagged
Section titled “tagged”
readonlytagged:boolean
Defined in: node_modules/.bun/drizzle-orm@1.0.0-rc.4+7a682c4b82ae109f/node_modules/drizzle-orm/pg-core/async/db.d.ts:28
Inherited from
Section titled “Inherited from”PgAsyncTransaction.tagged
[entityKind]
Section titled “[entityKind]”
readonlystatic[entityKind]:string="PgwasmTransaction"
Defined in: packages/pgwasm/src/drizzle/session.ts:104
Overrides
Section titled “Overrides”PgAsyncTransaction.[entityKind]
Methods
Section titled “Methods”$count()
Section titled “$count()”$count(
source,filters?):PgAsyncCountBuilder
Defined in: node_modules/.bun/drizzle-orm@1.0.0-rc.4+7a682c4b82ae109f/node_modules/drizzle-orm/pg-core/async/db.d.ts:73
Parameters
Section titled “Parameters”source
Section titled “source”SQLWrapper<unknown> | PgTable<TableConfig> | SQL<unknown> | PgViewBase<string, boolean, ColumnsSelection>
filters?
Section titled “filters?”SQL<unknown>
Returns
Section titled “Returns”PgAsyncCountBuilder
Inherited from
Section titled “Inherited from”PgAsyncTransaction.$count
delete()
Section titled “delete()”delete<
TTable>(table):PgAsyncDeleteBase<TTable,PgwasmQueryResultHKT>
Defined in: node_modules/.bun/drizzle-orm@1.0.0-rc.4+7a682c4b82ae109f/node_modules/drizzle-orm/pg-core/async/db.d.ts:281
Creates a delete query.
Calling this method without .where() clause will delete all rows in a table. The .where() clause specifies which rows should be deleted.
See docs: https://orm.drizzle.team/docs/delete
Type Parameters
Section titled “Type Parameters”TTable
Section titled “TTable”TTable extends PgTable<TableConfig>
Parameters
Section titled “Parameters”TTable
The table to delete from.
Returns
Section titled “Returns”PgAsyncDeleteBase<TTable, PgwasmQueryResultHKT>
Example
Section titled “Example”// Delete all rows in the 'cars' tableawait db.delete(cars);
// Delete rows with filters and conditionsawait db.delete(cars).where(eq(cars.color, 'green'));
// Delete with returning clauseconst deletedCar: Car[] = await db.delete(cars) .where(eq(cars.id, 1)) .returning();Inherited from
Section titled “Inherited from”PgAsyncTransaction.delete
execute()
Section titled “execute()”execute<
TRow>(query):PgAsyncRaw<Results<Assume<TRow,Row>>>
Defined in: node_modules/.bun/drizzle-orm@1.0.0-rc.4+7a682c4b82ae109f/node_modules/drizzle-orm/pg-core/async/db.d.ts:283
Type Parameters
Section titled “Type Parameters”TRow extends Record<string, unknown> = Record<string, unknown>
Parameters
Section titled “Parameters”string | SQLWrapper<unknown>
Returns
Section titled “Returns”PgAsyncRaw<Results<Assume<TRow, Row>>>
Inherited from
Section titled “Inherited from”PgAsyncTransaction.execute
insert()
Section titled “insert()”insert<
TTable>(table):PgInsertBuilder<TTable,PgwasmQueryResultHKT,false,PgAsyncInsertHKT>
Defined in: node_modules/.bun/drizzle-orm@1.0.0-rc.4+7a682c4b82ae109f/node_modules/drizzle-orm/pg-core/async/db.d.ts:256
Creates an insert query.
Calling this method will create new rows in a table. Use .values() method to specify which values to insert.
See docs: https://orm.drizzle.team/docs/insert
Type Parameters
Section titled “Type Parameters”TTable
Section titled “TTable”TTable extends PgTable<TableConfig>
Parameters
Section titled “Parameters”TTable
The table to insert into.
Returns
Section titled “Returns”PgInsertBuilder<TTable, PgwasmQueryResultHKT, false, PgAsyncInsertHKT>
Example
Section titled “Example”// Insert one rowawait db.insert(cars).values({ brand: 'BMW' });
// Insert multiple rowsawait db.insert(cars).values([{ brand: 'BMW' }, { brand: 'Porsche' }]);
// Insert with returning clauseconst insertedCar: Car[] = await db.insert(cars) .values({ brand: 'BMW' }) .returning();Inherited from
Section titled “Inherited from”PgAsyncTransaction.insert
refreshMaterializedView()
Section titled “refreshMaterializedView()”refreshMaterializedView<
TView>(view):PgAsyncRefreshMaterializedView<PgwasmQueryResultHKT>
Defined in: node_modules/.bun/drizzle-orm@1.0.0-rc.4+7a682c4b82ae109f/node_modules/drizzle-orm/pg-core/async/db.d.ts:282
Type Parameters
Section titled “Type Parameters”TView extends PgMaterializedView<string, boolean, ColumnsSelection>
Parameters
Section titled “Parameters”TView
Returns
Section titled “Returns”PgAsyncRefreshMaterializedView<PgwasmQueryResultHKT>
Inherited from
Section titled “Inherited from”PgAsyncTransaction.refreshMaterializedView
rollback()
Section titled “rollback()”rollback():
never
Defined in: node_modules/.bun/drizzle-orm@1.0.0-rc.4+7a682c4b82ae109f/node_modules/drizzle-orm/pg-core/async/session.d.ts:46
Returns
Section titled “Returns”never
Inherited from
Section titled “Inherited from”PgAsyncTransaction.rollback
select()
Section titled “select()”Call Signature
Section titled “Call Signature”select():
PgAsyncSelectBuilder<undefined>
Defined in: node_modules/.bun/drizzle-orm@1.0.0-rc.4+7a682c4b82ae109f/node_modules/drizzle-orm/pg-core/async/db.d.ts:149
Creates a select query.
Calling this method with no arguments will select all columns from the table. Pass a selection object to specify the columns you want to select.
Use .from() method to specify which table to select from.
See docs: https://orm.drizzle.team/docs/select
Returns
Section titled “Returns”PgAsyncSelectBuilder<undefined>
Example
Section titled “Example”// Select all columns and all rows from the 'cars' tableconst allCars: Car[] = await db.select().from(cars);
// Select specific columns and all rows from the 'cars' tableconst carsIdsAndBrands: { id: number; brand: string }[] = await db.select({ id: cars.id, brand: cars.brand}) .from(cars);Like in SQL, you can use arbitrary expressions as selection fields, not just table columns:
// Select specific columns along with expression and all rows from the 'cars' tableconst carsIdsAndLowerNames: { id: number; lowerBrand: string }[] = await db.select({ id: cars.id, lowerBrand: sql<string>`lower(${cars.brand})`,}) .from(cars);Inherited from
Section titled “Inherited from”PgAsyncTransaction.select
Call Signature
Section titled “Call Signature”select<
TSelection>(fields):PgAsyncSelectBuilder<TSelection>
Defined in: node_modules/.bun/drizzle-orm@1.0.0-rc.4+7a682c4b82ae109f/node_modules/drizzle-orm/pg-core/async/db.d.ts:150
Creates a select query.
Calling this method with no arguments will select all columns from the table. Pass a selection object to specify the columns you want to select.
Use .from() method to specify which table to select from.
See docs: https://orm.drizzle.team/docs/select
Type Parameters
Section titled “Type Parameters”TSelection
Section titled “TSelection”TSelection extends SelectedFields
Parameters
Section titled “Parameters”fields
Section titled “fields”TSelection
The selection object.
Returns
Section titled “Returns”PgAsyncSelectBuilder<TSelection>
Example
Section titled “Example”// Select all columns and all rows from the 'cars' tableconst allCars: Car[] = await db.select().from(cars);
// Select specific columns and all rows from the 'cars' tableconst carsIdsAndBrands: { id: number; brand: string }[] = await db.select({ id: cars.id, brand: cars.brand}) .from(cars);Like in SQL, you can use arbitrary expressions as selection fields, not just table columns:
// Select specific columns along with expression and all rows from the 'cars' tableconst carsIdsAndLowerNames: { id: number; lowerBrand: string }[] = await db.select({ id: cars.id, lowerBrand: sql<string>`lower(${cars.brand})`,}) .from(cars);Inherited from
Section titled “Inherited from”PgAsyncTransaction.select
selectDistinct()
Section titled “selectDistinct()”Call Signature
Section titled “Call Signature”selectDistinct():
PgAsyncSelectBuilder<undefined>
Defined in: node_modules/.bun/drizzle-orm@1.0.0-rc.4+7a682c4b82ae109f/node_modules/drizzle-orm/pg-core/async/db.d.ts:175
Adds distinct expression to the select query.
Calling this method will return only unique values. When multiple columns are selected, it returns rows with unique combinations of values in these columns.
Use .from() method to specify which table to select from.
See docs: https://orm.drizzle.team/docs/select#distinct
Returns
Section titled “Returns”PgAsyncSelectBuilder<undefined>
Example
Section titled “Example”// Select all unique rows from the 'cars' tableawait db.selectDistinct() .from(cars) .orderBy(cars.id, cars.brand, cars.color);
// Select all unique brands from the 'cars' tableawait db.selectDistinct({ brand: cars.brand }) .from(cars) .orderBy(cars.brand);Inherited from
Section titled “Inherited from”PgAsyncTransaction.selectDistinct
Call Signature
Section titled “Call Signature”selectDistinct<
TSelection>(fields):PgAsyncSelectBuilder<TSelection>
Defined in: node_modules/.bun/drizzle-orm@1.0.0-rc.4+7a682c4b82ae109f/node_modules/drizzle-orm/pg-core/async/db.d.ts:176
Adds distinct expression to the select query.
Calling this method will return only unique values. When multiple columns are selected, it returns rows with unique combinations of values in these columns.
Use .from() method to specify which table to select from.
See docs: https://orm.drizzle.team/docs/select#distinct
Type Parameters
Section titled “Type Parameters”TSelection
Section titled “TSelection”TSelection extends SelectedFields
Parameters
Section titled “Parameters”fields
Section titled “fields”TSelection
The selection object.
Returns
Section titled “Returns”PgAsyncSelectBuilder<TSelection>
Example
Section titled “Example”// Select all unique rows from the 'cars' tableawait db.selectDistinct() .from(cars) .orderBy(cars.id, cars.brand, cars.color);
// Select all unique brands from the 'cars' tableawait db.selectDistinct({ brand: cars.brand }) .from(cars) .orderBy(cars.brand);Inherited from
Section titled “Inherited from”PgAsyncTransaction.selectDistinct
selectDistinctOn()
Section titled “selectDistinctOn()”Call Signature
Section titled “Call Signature”selectDistinctOn(
on):PgAsyncSelectBuilder<undefined>
Defined in: node_modules/.bun/drizzle-orm@1.0.0-rc.4+7a682c4b82ae109f/node_modules/drizzle-orm/pg-core/async/db.d.ts:202
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.
See docs: https://orm.drizzle.team/docs/select#distinct
Parameters
Section titled “Parameters”(SQLWrapper<unknown> | PgColumn<any, PgColumnBaseConfig<any>, { }>)[]
The expression defining uniqueness.
Returns
Section titled “Returns”PgAsyncSelectBuilder<undefined>
Example
Section titled “Example”// Select the first row for each unique brand from the 'cars' tableawait db.selectDistinctOn([cars.brand]) .from(cars) .orderBy(cars.brand);
// Selects the first occurrence of each unique car brand along with its color from the 'cars' tableawait db.selectDistinctOn([cars.brand], { brand: cars.brand, color: cars.color }) .from(cars) .orderBy(cars.brand, cars.color);Inherited from
Section titled “Inherited from”PgAsyncTransaction.selectDistinctOn
Call Signature
Section titled “Call Signature”selectDistinctOn<
TSelection>(on,fields):PgAsyncSelectBuilder<TSelection>
Defined in: node_modules/.bun/drizzle-orm@1.0.0-rc.4+7a682c4b82ae109f/node_modules/drizzle-orm/pg-core/async/db.d.ts:203
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.
See docs: https://orm.drizzle.team/docs/select#distinct
Type Parameters
Section titled “Type Parameters”TSelection
Section titled “TSelection”TSelection extends SelectedFields
Parameters
Section titled “Parameters”(SQLWrapper<unknown> | PgColumn<any, PgColumnBaseConfig<any>, { }>)[]
The expression defining uniqueness.
fields
Section titled “fields”TSelection
The selection object.
Returns
Section titled “Returns”PgAsyncSelectBuilder<TSelection>
Example
Section titled “Example”// Select the first row for each unique brand from the 'cars' tableawait db.selectDistinctOn([cars.brand]) .from(cars) .orderBy(cars.brand);
// Selects the first occurrence of each unique car brand along with its color from the 'cars' tableawait db.selectDistinctOn([cars.brand], { brand: cars.brand, color: cars.color }) .from(cars) .orderBy(cars.brand, cars.color);Inherited from
Section titled “Inherited from”PgAsyncTransaction.selectDistinctOn
setTransaction()
Section titled “setTransaction()”setTransaction(
config):Promise<unknown>
Defined in: node_modules/.bun/drizzle-orm@1.0.0-rc.4+7a682c4b82ae109f/node_modules/drizzle-orm/pg-core/async/session.d.ts:47
Parameters
Section titled “Parameters”config
Section titled “config”PgTransactionConfig
Returns
Section titled “Returns”Promise<unknown>
Inherited from
Section titled “Inherited from”PgAsyncTransaction.setTransaction
transaction()
Section titled “transaction()”transaction<
T>(transaction):Promise<T>
Defined in: packages/pgwasm/src/drizzle/session.ts:120
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”transaction
Section titled “transaction”(tx) => Promise<T>
Returns
Section titled “Returns”Promise<T>
Overrides
Section titled “Overrides”PgAsyncTransaction.transaction
update()
Section titled “update()”update<
TTable>(table):PgUpdateBuilder<TTable,PgwasmQueryResultHKT,PgAsyncUpdateHKT>
Defined in: node_modules/.bun/drizzle-orm@1.0.0-rc.4+7a682c4b82ae109f/node_modules/drizzle-orm/pg-core/async/db.d.ts:231
Creates an update query.
Calling this method without .where() clause will update all rows in a table. The .where() clause specifies which rows should be updated.
Use .set() method to specify which values to update.
See docs: https://orm.drizzle.team/docs/update
Type Parameters
Section titled “Type Parameters”TTable
Section titled “TTable”TTable extends PgTable<TableConfig>
Parameters
Section titled “Parameters”TTable
The table to update.
Returns
Section titled “Returns”PgUpdateBuilder<TTable, PgwasmQueryResultHKT, PgAsyncUpdateHKT>
Example
Section titled “Example”// Update all rows in the 'cars' tableawait db.update(cars).set({ color: 'red' });
// Update rows with filters and conditionsawait db.update(cars).set({ color: 'red' }).where(eq(cars.brand, 'BMW'));
// Update with returning clauseconst updatedCar: Car[] = await db.update(cars) .set({ color: 'red' }) .where(eq(cars.id, 1)) .returning();Inherited from
Section titled “Inherited from”PgAsyncTransaction.update
with()
Section titled “with()”with(…
queries):object
Defined in: node_modules/.bun/drizzle-orm@1.0.0-rc.4+7a682c4b82ae109f/node_modules/drizzle-orm/pg-core/async/db.d.ts:96
Incorporates a previously defined CTE (using $with) into the main query.
This method allows the main query to reference a temporary named result set.
See docs: https://orm.drizzle.team/docs/select#with-clause
Parameters
Section titled “Parameters”queries
Section titled “queries”…WithSubquery<string, Record<string, unknown>>[]
The CTEs to incorporate into the main query.
Returns
Section titled “Returns”object
delete
Section titled “delete”delete: <
TTable>(table) =>PgAsyncDeleteBase<TTable,PgwasmQueryResultHKT>
Type Parameters
Section titled “Type Parameters”TTable
Section titled “TTable”TTable extends PgTable<TableConfig>
Parameters
Section titled “Parameters”TTable
Returns
Section titled “Returns”PgAsyncDeleteBase<TTable, PgwasmQueryResultHKT>
insert
Section titled “insert”insert: <
TTable>(table) =>PgInsertBuilder<TTable,PgwasmQueryResultHKT,false,PgAsyncInsertHKT>
Type Parameters
Section titled “Type Parameters”TTable
Section titled “TTable”TTable extends PgTable<TableConfig>
Parameters
Section titled “Parameters”TTable
Returns
Section titled “Returns”PgInsertBuilder<TTable, PgwasmQueryResultHKT, false, PgAsyncInsertHKT>
select
Section titled “select”select: {():
PgAsyncSelectBuilder<undefined>; <TSelection>(fields):PgAsyncSelectBuilder<TSelection>; }
Call Signature
Section titled “Call Signature”():
PgAsyncSelectBuilder<undefined>
Returns
Section titled “Returns”PgAsyncSelectBuilder<undefined>
Call Signature
Section titled “Call Signature”<
TSelection>(fields):PgAsyncSelectBuilder<TSelection>
Type Parameters
Section titled “Type Parameters”TSelection
Section titled “TSelection”TSelection extends SelectedFields
Parameters
Section titled “Parameters”fields
Section titled “fields”TSelection
Returns
Section titled “Returns”PgAsyncSelectBuilder<TSelection>
selectDistinct
Section titled “selectDistinct”selectDistinct: {():
PgAsyncSelectBuilder<undefined>; <TSelection>(fields):PgAsyncSelectBuilder<TSelection>; }
Call Signature
Section titled “Call Signature”():
PgAsyncSelectBuilder<undefined>
Returns
Section titled “Returns”PgAsyncSelectBuilder<undefined>
Call Signature
Section titled “Call Signature”<
TSelection>(fields):PgAsyncSelectBuilder<TSelection>
Type Parameters
Section titled “Type Parameters”TSelection
Section titled “TSelection”TSelection extends SelectedFields
Parameters
Section titled “Parameters”fields
Section titled “fields”TSelection
Returns
Section titled “Returns”PgAsyncSelectBuilder<TSelection>
selectDistinctOn
Section titled “selectDistinctOn”selectDistinctOn: {(
on):PgAsyncSelectBuilder<undefined>; <TSelection>(on,fields):PgAsyncSelectBuilder<TSelection>; }
Call Signature
Section titled “Call Signature”(
on):PgAsyncSelectBuilder<undefined>
Parameters
Section titled “Parameters”(SQLWrapper<unknown> | PgColumn<any, PgColumnBaseConfig<any>, { }>)[]
Returns
Section titled “Returns”PgAsyncSelectBuilder<undefined>
Call Signature
Section titled “Call Signature”<
TSelection>(on,fields):PgAsyncSelectBuilder<TSelection>
Type Parameters
Section titled “Type Parameters”TSelection
Section titled “TSelection”TSelection extends SelectedFields
Parameters
Section titled “Parameters”(SQLWrapper<unknown> | PgColumn<any, PgColumnBaseConfig<any>, { }>)[]
fields
Section titled “fields”TSelection
Returns
Section titled “Returns”PgAsyncSelectBuilder<TSelection>
update
Section titled “update”update: <
TTable>(table) =>PgUpdateBuilder<TTable,PgwasmQueryResultHKT,PgAsyncUpdateHKT>
Type Parameters
Section titled “Type Parameters”TTable
Section titled “TTable”TTable extends PgTable<TableConfig>
Parameters
Section titled “Parameters”TTable
Returns
Section titled “Returns”PgUpdateBuilder<TTable, PgwasmQueryResultHKT, PgAsyncUpdateHKT>
Example
Section titled “Example”// Define a subquery 'sq' as a CTE using $withconst 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 itconst result = await db.with(sq).select().from(sq);Inherited from
Section titled “Inherited from”PgAsyncTransaction.with