Skip to content

PgwasmTransaction

Defined in: packages/pgwasm/src/drizzle/session.ts:100

TRelations extends AnyRelations

new PgwasmTransaction<TRelations>(dialect, session, relations, nestedIndex, parseRqbJson): PgwasmTransaction<TRelations>

Defined in: packages/pgwasm/src/drizzle/session.ts:108

PgDialect

PgwasmSession<TRelations>

TRelations

number | undefined

boolean | undefined

PgwasmTransaction<TRelations>

PgAsyncTransaction<PgwasmQueryResultHKT, TRelations>.constructor

readonly _: object

Defined in: node_modules/.bun/drizzle-orm@1.0.0-rc.5+94d79d82a35f7da4/node_modules/drizzle-orm/pg-core/async/db.d.ts:353

readonly relations: TRelations

readonly session: PgAsyncSession<PgwasmQueryResultHKT, TRelations>

PgAsyncTransaction._


$cache: object

Defined in: node_modules/.bun/drizzle-orm@1.0.0-rc.5+94d79d82a35f7da4/node_modules/drizzle-orm/pg-core/async/db.d.ts:78

invalidate: (params) => Promise<void>

Invoked if insert, update, delete was invoked

MutationOption

Promise<void>

PgAsyncTransaction.$cache


$with: WithBuilder

Defined in: node_modules/.bun/drizzle-orm@1.0.0-rc.5+94d79d82a35f7da4/node_modules/drizzle-orm/pg-core/async/db.d.ts:76

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.

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

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

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

PgAsyncTransaction.$with


query: { [K in string | number | symbol]: RelationalQueryBuilder<TRelations, TRelations[K], PgAsyncRelationalQueryHKT> }

Defined in: node_modules/.bun/drizzle-orm@1.0.0-rc.5+94d79d82a35f7da4/node_modules/drizzle-orm/pg-core/async/db.d.ts:38

PgAsyncTransaction.query


readonly tagged: boolean

Defined in: node_modules/.bun/drizzle-orm@1.0.0-rc.5+94d79d82a35f7da4/node_modules/drizzle-orm/pg-core/async/db.d.ts:31

PgAsyncTransaction.tagged


readonly static [entityKind]: string = "PgwasmTransaction"

Defined in: packages/pgwasm/src/drizzle/session.ts:104

PgAsyncTransaction.[entityKind]

$count(source, filters?): PgAsyncCountBuilder

Defined in: node_modules/.bun/drizzle-orm@1.0.0-rc.5+94d79d82a35f7da4/node_modules/drizzle-orm/pg-core/async/db.d.ts:77

SQLWrapper<unknown> | PgTable<TableConfig> | SQL<unknown> | PgViewBase<ViewConfig<ColumnsSelection>>

SQL<unknown>

PgAsyncCountBuilder

PgAsyncTransaction.$count


delete<TTable>(table): PgAsyncDeleteBase<TTable, PgwasmQueryResultHKT>

Defined in: node_modules/.bun/drizzle-orm@1.0.0-rc.5+94d79d82a35f7da4/node_modules/drizzle-orm/pg-core/async/db.d.ts:292

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

TTable extends PgTable<TableConfig>

TTable

The table to delete from.

PgAsyncDeleteBase<TTable, PgwasmQueryResultHKT>

// Delete all rows in the 'cars' table
await db.delete(cars);
// Delete rows with filters and conditions
await db.delete(cars).where(eq(cars.color, 'green'));
// Delete with returning clause
const deletedCar: Car[] = await db.delete(cars)
.where(eq(cars.id, 1))
.returning();

PgAsyncTransaction.delete


execute<TRow>(query, mode): PgAsyncRaw<TRow[]>

Defined in: node_modules/.bun/drizzle-orm@1.0.0-rc.5+94d79d82a35f7da4/node_modules/drizzle-orm/pg-core/async/db.d.ts:308

Executes raw SQL query, responding with rows as arrays of values

Types assume single statement is executed per query

TRow extends unknown[] = unknown[]

string | SQLWrapper<unknown>

SQL query to execute

"arrays"

'arrays'

PgAsyncRaw<TRow[]>

// [number, string][]
const rows = await db.execute<[number, string]>(sql`select ${users.id}, ${users.name} from ${users}`, 'arrays');

PgAsyncTransaction.execute

execute<TRow>(query, mode): PgAsyncRaw<TRow[]>

Defined in: node_modules/.bun/drizzle-orm@1.0.0-rc.5+94d79d82a35f7da4/node_modules/drizzle-orm/pg-core/async/db.d.ts:323

Executes raw SQL query, responding with rows as objects

Types assume single statement is executed per query

TRow extends Record<string, any> = Record<string, unknown>

string | SQLWrapper<unknown>

SQL query to execute

"objects"

'objects'

PgAsyncRaw<TRow[]>

// { id: number; name: string }[]
const rows = await db.execute<{ id: number; name: string }>(sql`select ${users.id}, ${users.name} from ${users}`, 'objects');

PgAsyncTransaction.execute

execute<TRow>(query, mode?): PgAsyncRaw<Results<Assume<TRow, Row>>>

Defined in: node_modules/.bun/drizzle-orm@1.0.0-rc.5+94d79d82a35f7da4/node_modules/drizzle-orm/pg-core/async/db.d.ts:349

Executes raw SQL query, returning driver’s raw response

Row type argument defines the type of the response:

  • 'unknown' (default) - any response of the driver
  • never - response of a statement that returns no rows
  • object shape - response with rows of given shape

Typed call assumes single statement is executed per query

TRow extends Record<string, any> | "unknown" = "unknown"

string | SQLWrapper<unknown>

SQL query to execute

"raw"

'raw' (default)

PgAsyncRaw<Results<Assume<TRow, Row>>>

// Any response of the driver
const response = await db.execute(sql`select * from ${users}`);
// Response of a statement that returns no rows
const updated = await db.execute<never>(sql`update ${users} set ${users.name} = ${'John'}`);
// Response with rows of given shape
const selected = await db.execute<{ id: number; name: string }>(sql`select ${users.id}, ${users.name} from ${users}`);

PgAsyncTransaction.execute


insert<TTable, TColumnList, TRequiredKeys>(table, …columns): PgInsertBuilder<TTable, PgwasmQueryResultHKT, TColumnList extends [] ? "all" : TColumnList, false, PgAsyncInsertHKT>

Defined in: node_modules/.bun/drizzle-orm@1.0.0-rc.5+94d79d82a35f7da4/node_modules/drizzle-orm/pg-core/async/db.d.ts:265

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

TTable extends PgTable<TableConfig>

TColumnList extends (keyof { [Key in string as RequiredKeyOnly<Key, TTable[“_”][“columns”][Key]>]: TTable[“_”][“columns”][Key][“_”][“notNull”] extends true ? TTable[“_”][“columns”][Key][“_”][“data”] : (…)[(…)][“columns”][Key][“_”][“data”] | null } | keyof { [Key in string as OptionalKeyOnly<Key, TTable[“_”][“columns”][Key], true>]?: (…)[(…)][“columns”][Key][“_”][“notNull”] extends true ? (…)[(…)][“columns”][Key][“_”][“data”] : (…)[(…)][Key][“_”][“data”] | null })[] = []

TRequiredKeys extends string = RequiredInsertKeys<TTable>

TTable

The table to insert into.

…TColumnList extends [] ? [] : IsNever<TRequiredKeys> extends true ? TColumnList & NoDuplicateColumns<TColumnList, never> : [TRequiredKeys] extends [TColumnList[number]] ? TColumnList & NoDuplicateColumns<TColumnList, never> : DrizzleTypeError<`Column selection is missing following required columns: ${JoinTuple<UnionToTuple<`"${Exclude<TRequiredKeys, (...)[(...)]>}"`, LastInUnion<`"${Exclude<(...), (...)>}"`>>, ", ">}`>[]

PgInsertBuilder<TTable, PgwasmQueryResultHKT, TColumnList extends [] ? "all" : TColumnList, false, PgAsyncInsertHKT>

// Insert one row
await db.insert(cars).values({ brand: 'BMW' });
// Insert multiple rows
await db.insert(cars).values([{ brand: 'BMW' }, { brand: 'Porsche' }]);
// Insert only selected columns
await db.insert(cars, 'brand', 'productionYear').values([{ brand: 'BMW', productionYear: 1995 }, { brand: 'Porsche', productionYear: 1989 }]);
// Insert with returning clause
const insertedCar: Car[] = await db.insert(cars)
.values({ brand: 'BMW' })
.returning();

PgAsyncTransaction.insert


refreshMaterializedView<TView>(view): PgAsyncRefreshMaterializedView<PgwasmQueryResultHKT>

Defined in: node_modules/.bun/drizzle-orm@1.0.0-rc.5+94d79d82a35f7da4/node_modules/drizzle-orm/pg-core/async/db.d.ts:293

TView extends PgMaterializedView<ViewConfig<ColumnsSelection>>

TView

PgAsyncRefreshMaterializedView<PgwasmQueryResultHKT>

PgAsyncTransaction.refreshMaterializedView


rollback(): never

Defined in: node_modules/.bun/drizzle-orm@1.0.0-rc.5+94d79d82a35f7da4/node_modules/drizzle-orm/pg-core/async/session.d.ts:40

never

PgAsyncTransaction.rollback


select(): PgAsyncSelectBuilder<undefined>

Defined in: node_modules/.bun/drizzle-orm@1.0.0-rc.5+94d79d82a35f7da4/node_modules/drizzle-orm/pg-core/async/db.d.ts:155

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

PgAsyncSelectBuilder<undefined>

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

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

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

PgAsyncTransaction.select

select<TSelection>(fields): PgAsyncSelectBuilder<TSelection>

Defined in: node_modules/.bun/drizzle-orm@1.0.0-rc.5+94d79d82a35f7da4/node_modules/drizzle-orm/pg-core/async/db.d.ts:156

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

TSelection extends SelectedFields

TSelection

The selection object.

PgAsyncSelectBuilder<TSelection>

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

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

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

PgAsyncTransaction.select


selectDistinct(): PgAsyncSelectBuilder<undefined>

Defined in: node_modules/.bun/drizzle-orm@1.0.0-rc.5+94d79d82a35f7da4/node_modules/drizzle-orm/pg-core/async/db.d.ts:181

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

PgAsyncSelectBuilder<undefined>

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

PgAsyncTransaction.selectDistinct

selectDistinct<TSelection>(fields): PgAsyncSelectBuilder<TSelection>

Defined in: node_modules/.bun/drizzle-orm@1.0.0-rc.5+94d79d82a35f7da4/node_modules/drizzle-orm/pg-core/async/db.d.ts:182

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

TSelection extends SelectedFields

TSelection

The selection object.

PgAsyncSelectBuilder<TSelection>

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

PgAsyncTransaction.selectDistinct


selectDistinctOn(on): PgAsyncSelectBuilder<undefined>

Defined in: node_modules/.bun/drizzle-orm@1.0.0-rc.5+94d79d82a35f7da4/node_modules/drizzle-orm/pg-core/async/db.d.ts:208

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

(SQLWrapper<unknown> | PgColumn<any, PgColumnBaseConfig<any>, { }>)[]

The expression defining uniqueness.

PgAsyncSelectBuilder<undefined>

// Select the first row for each unique brand from the 'cars' table
await 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' table
await db.selectDistinctOn([cars.brand], { brand: cars.brand, color: cars.color })
.from(cars)
.orderBy(cars.brand, cars.color);

PgAsyncTransaction.selectDistinctOn

selectDistinctOn<TSelection>(on, fields): PgAsyncSelectBuilder<TSelection>

Defined in: node_modules/.bun/drizzle-orm@1.0.0-rc.5+94d79d82a35f7da4/node_modules/drizzle-orm/pg-core/async/db.d.ts:209

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

TSelection extends SelectedFields

(SQLWrapper<unknown> | PgColumn<any, PgColumnBaseConfig<any>, { }>)[]

The expression defining uniqueness.

TSelection

The selection object.

PgAsyncSelectBuilder<TSelection>

// Select the first row for each unique brand from the 'cars' table
await 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' table
await db.selectDistinctOn([cars.brand], { brand: cars.brand, color: cars.color })
.from(cars)
.orderBy(cars.brand, cars.color);

PgAsyncTransaction.selectDistinctOn


setTransaction(config): Promise<unknown>

Defined in: node_modules/.bun/drizzle-orm@1.0.0-rc.5+94d79d82a35f7da4/node_modules/drizzle-orm/pg-core/async/session.d.ts:41

PgTransactionConfig

Promise<unknown>

PgAsyncTransaction.setTransaction


transaction<T>(transaction): Promise<T>

Defined in: packages/pgwasm/src/drizzle/session.ts:120

T

(tx) => Promise<T>

Promise<T>

PgAsyncTransaction.transaction


update<TTable>(table): PgUpdateBuilder<TTable, PgwasmQueryResultHKT, PgAsyncUpdateHKT>

Defined in: node_modules/.bun/drizzle-orm@1.0.0-rc.5+94d79d82a35f7da4/node_modules/drizzle-orm/pg-core/async/db.d.ts:237

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

TTable extends PgTable<TableConfig>

TTable

The table to update.

PgUpdateBuilder<TTable, PgwasmQueryResultHKT, PgAsyncUpdateHKT>

// Update all rows in the 'cars' table
await db.update(cars).set({ color: 'red' });
// Update rows with filters and conditions
await db.update(cars).set({ color: 'red' }).where(eq(cars.brand, 'BMW'));
// Update with returning clause
const updatedCar: Car[] = await db.update(cars)
.set({ color: 'red' })
.where(eq(cars.id, 1))
.returning();

PgAsyncTransaction.update


with(…queries): object

Defined in: node_modules/.bun/drizzle-orm@1.0.0-rc.5+94d79d82a35f7da4/node_modules/drizzle-orm/pg-core/async/db.d.ts:100

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

…WithSubquery<string, Record<string, unknown>>[]

The CTEs to incorporate into the main query.

object

delete: <TTable>(table) => PgAsyncDeleteBase<TTable, PgwasmQueryResultHKT>

TTable extends PgTable<TableConfig>

TTable

PgAsyncDeleteBase<TTable, PgwasmQueryResultHKT>

insert: <TTable, TColumnList, TRequiredKeys>(table, …columns) => PgInsertBuilder<TTable, PgwasmQueryResultHKT, TColumnList extends [] ? "all" : TColumnList, false, PgAsyncInsertHKT>

TTable extends PgTable<TableConfig>

TColumnList extends (keyof { [Key in string as RequiredKeyOnly<Key, TTable[“_”][“columns”][Key]>]: (…)[(…)][Key][“_”][“notNull”] extends true ? (…)[(…)][Key][“_”][“data”] : (…)[(…)][“_”][“data”] | null } | keyof { [Key in string as OptionalKeyOnly<Key, TTable[“_”][“columns”][Key], true>]?: (…)[(…)][“_”][“notNull”] extends true ? (…)[(…)][“_”][“data”] : (…)[(…)][“data”] | null })[] = []

TRequiredKeys extends string = RequiredInsertKeys<TTable>

TTable

…TColumnList extends [] ? [] : IsNever<TRequiredKeys> extends true ? TColumnList & NoDuplicateColumns<TColumnList, never> : [TRequiredKeys] extends [TColumnList[number]] ? TColumnList & NoDuplicateColumns<TColumnList, never> : DrizzleTypeError<`Column selection is missing following required columns: ${JoinTuple<UnionToTuple<`"${(...)}"`, LastInUnion<(...)>>, ", ">}`>[]

PgInsertBuilder<TTable, PgwasmQueryResultHKT, TColumnList extends [] ? "all" : TColumnList, false, PgAsyncInsertHKT>

select: {(): PgAsyncSelectBuilder<undefined>; <TSelection>(fields): PgAsyncSelectBuilder<TSelection>; }

(): PgAsyncSelectBuilder<undefined>

PgAsyncSelectBuilder<undefined>

<TSelection>(fields): PgAsyncSelectBuilder<TSelection>

TSelection extends SelectedFields

TSelection

PgAsyncSelectBuilder<TSelection>

selectDistinct: {(): PgAsyncSelectBuilder<undefined>; <TSelection>(fields): PgAsyncSelectBuilder<TSelection>; }

(): PgAsyncSelectBuilder<undefined>

PgAsyncSelectBuilder<undefined>

<TSelection>(fields): PgAsyncSelectBuilder<TSelection>

TSelection extends SelectedFields

TSelection

PgAsyncSelectBuilder<TSelection>

selectDistinctOn: {(on): PgAsyncSelectBuilder<undefined>; <TSelection>(on, fields): PgAsyncSelectBuilder<TSelection>; }

(on): PgAsyncSelectBuilder<undefined>

(SQLWrapper<unknown> | PgColumn<any, PgColumnBaseConfig<any>, { }>)[]

PgAsyncSelectBuilder<undefined>

<TSelection>(on, fields): PgAsyncSelectBuilder<TSelection>

TSelection extends SelectedFields

(SQLWrapper<unknown> | PgColumn<any, PgColumnBaseConfig<any>, { }>)[]

TSelection

PgAsyncSelectBuilder<TSelection>

update: <TTable>(table) => PgUpdateBuilder<TTable, PgwasmQueryResultHKT, PgAsyncUpdateHKT>

TTable extends PgTable<TableConfig>

TTable

PgUpdateBuilder<TTable, PgwasmQueryResultHKT, PgAsyncUpdateHKT>

// Define a subquery 'sq' as a CTE using $with
const sq = db.$with('sq').as(db.select().from(users).where(eq(users.id, 42)));
// Incorporate the CTE 'sq' into the main query and select from it
const result = await db.with(sq).select().from(sq);

PgAsyncTransaction.with


static [hasInstance](value): boolean

Defined in: node_modules/.bun/drizzle-orm@1.0.0-rc.5+94d79d82a35f7da4/node_modules/drizzle-orm/pg-core/async/db.d.ts:33

unknown

boolean

PgAsyncTransaction.[hasInstance]