Skip to main content

Interface: UnitOfWorkApi

Extends

  • AsyncDisposable

Methods

[asyncDispose]()

[asyncDispose](): PromiseLike<void>

Returns

PromiseLike<void>

Inherited from

AsyncDisposable.[asyncDispose]

Defined in

node_modules/.pnpm/@types+node@20.14.10/node_modules/@types/node/globals.d.ts:121


add()

add(entities)

add(...entities: readonly object[]): Promise<void>

Adds one or more entities in this unit of work. The entities will be inserted into the database when the unit of work is committed. If the corresponding entity type is configured with a client-side key generator, then keys will be generated and set on the entities; otherwise, the entities will be assigned temporary keys.

Parameters
ParameterTypeDescription
...entitiesreadonly object[]One or more entity instances.
Returns

Promise<void>

A promise that resolves once the entities have been added.

Example
const blog1 = new Blog({
title: 'My first blog',
content: 'This is the content of my first blog',
});

const blog2 = new Blog({
title: 'My second blog',
content: 'This is the content of my second blog',
});

await uow.add(blog1, blog2);
Defined in

packages/verse-core/src/uow.ts:428

add(entityName, entities)

add(entityName: string, ...entities: readonly object[]): Promise<void>

Adds one or more entities in this unit of work. The entities will be inserted into the database when the unit of work is committed. If the corresponding entity type is configured with a client-side key generator, then keys will be generated and set on the entities; otherwise, the entities will be assigned temporary keys.

Parameters
ParameterTypeDescription
entityNamestringThe name of the entity model.
...entitiesreadonly object[]One or more entity instances.
Returns

Promise<void>

A promise that resolves once the entities have been added.

Example
const blog1 = {
title: 'My first blog',
content: 'This is the content of my first blog',
};

const blog2 = {
title: 'My second blog',
content: 'This is the content of my second blog',
}l

await uow.add("Blog", blog1, blog2);
Defined in

packages/verse-core/src/uow.ts:455


commit()

commit(isolation?: IsolationLevel): Promise<void>

Commits all changes made in this unit of work to the database.

Parameters

ParameterTypeDescription
isolation?IsolationLevelOptional isolation level for the database transaction.

Returns

Promise<void>

A promise that resolves when the commit is successful.

Defined in

packages/verse-core/src/uow.ts:473


entry()

entry<Entity>(entity: Entity): undefined | EntityEntryApi<Entity>

Exposes operations that can be performed on an entity in this unit of work.

Type Parameters

Type Parameter
Entity extends object

Parameters

ParameterTypeDescription
entityEntityThe entity for which the entry API needs to be retrieved.

Returns

undefined | EntityEntryApi<Entity>

The entry API for the entity, or undefined if not found.

Example

uow.entry(album).setState('removed');

Defined in

packages/verse-core/src/uow.ts:484


remove()

remove(...entities: readonly object[]): void

Removes one or more entities in this unit of work. The entities will be deleted from the database when the unit of work is committed.

Parameters

ParameterTypeDescription
...entitiesreadonly object[]The entities to be removed.

Returns

void

Example

await uow.remove(blog1, blog2);

Defined in

packages/verse-core/src/uow.ts:466