CMS / foldkit-cms-drizzle

Transaction

namespace · packages/cms-drizzle/src/index.ts:106

const Transaction = { statements, drizzle }

Its type

type Transaction = <A, E>(
  work: Effect.Effect<A, E, DrizzleDatabase>,
) => Effect.Effect<A, E | RemoteServerError, DrizzleDatabase>

Runs some work so that it happened entirely or did not. Drizzle's own transactions differ by driver, so the application says which this is. It fails as the work does, or, when the database refuses the transaction itself, as a RemoteServerError that says nothing of why.

In the guides

Members

Transaction.statements

function · packages/cms-drizzle/src/index.ts:114

statements<A, E>(
  work: Effect.Effect<A, E, DrizzleDatabase>,
): Effect.Effect<A, E, DrizzleDatabase>

begin, the work, then commit or rollback, as statements. For a database that is one connection, such as a SQLite file, which it takes turns at: the operations of this package wait for one another. A write of your own on the same connection does not, so make it inside Transaction.statements too. Over a pool each statement may take a different connection: use drizzle there.

Transaction.drizzle

function · packages/cms-drizzle/src/index.ts:128

drizzle<A, E>(
  work: Effect.Effect<A, E, DrizzleDatabase>,
): Effect.Effect<A, RemoteServerError | E, DrizzleDatabase>

Drizzle's database.transaction, with the work given the transaction as its database. For a driver whose transactions are asynchronous: Postgres, libSQL.