Interface: UnitOfWorkApi
Extends
AsyncDisposable
Methods
[asyncDispose]
()
[asyncDispose]():
PromiseLike
<void
>
Returns
PromiseLike
<void
>
Inherited from
AsyncDisposable.[asyncDispose]
Source
node_modules/.pnpm/@types+node@20.12.11/node_modules/@types/node/globals.d.ts:120
add()
add(entities)
add(...
entities
: readonlyobject
[]):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
Parameter | Type | Description |
---|---|---|
...entities | readonly 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);
Source
packages/verse-core/src/uow.ts:428
add(entityName, entities)
add(
entityName
:string
, ...entities
: readonlyobject
[]):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
Parameter | Type | Description |
---|---|---|
entityName | string | The name of the entity model. |
...entities | readonly 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);
Source
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
Parameter | Type | Description |
---|---|---|
isolation ? | IsolationLevel | Optional isolation level for the database transaction. |
Returns
Promise ↗️
<void
>
A promise that resolves when the commit is successful.
Source
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
Parameter | Type | Description |
---|---|---|
entity | Entity | The 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');
Source
packages/verse-core/src/uow.ts:484
remove()
remove(...
entities
: readonlyobject
[]):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
Parameter | Type | Description |
---|---|---|
...entities | readonly object [] | The entities to be removed. |
Returns
void
Example
await uow.remove(blog1, blog2);