Remote / foldkit-remote-drizzle
withParentLock
function · packages/remote-drizzle/src/parentLock.ts:90
function withParentLock<A>(
table: PgTable,
idColumn: PgColumn,
parentIds: ReadonlyArray<string>,
body: (
tx: ParentLockTransaction,
lockedIds: ReadonlyArray<string>,
) => PromiseLike<A> | A,
): Effect.Effect<A, RemoteServerError, DrizzleDatabase>Run body inside a Postgres transaction that first locks parentIds on
table in ascending id order (SELECT ... FOR UPDATE), preventing deadlocks
across concurrent multi-parent writes and serializing aggregate rules.