Class: Verse<TEntities>
The top-level Verse object.
See verse for detailed usage information.
Type Parameters
Type Parameter | Default type |
---|---|
TEntities extends Entities | any |
Constructors
new Verse()
new Verse<
TEntities
>(config
:Config
,builder
:ModelBuilder
<TEntities
>):Verse
<TEntities
>
Creates a new instance.
Parameters
Parameter | Type | Description |
---|---|---|
config | Config | The configuration object. |
builder | ModelBuilder <TEntities > | The model builder object. |
Returns
Verse
<TEntities
>
Defined in
packages/verse-core/src/verse.ts:307
Properties
config
readonly
config:Config
The configuration object.
Defined in
packages/verse-core/src/verse.ts:308
database
readonly
database:DbOperations
Provides methods to perform various operations on the database.
Defined in
packages/verse-core/src/verse.ts:278
entities
readonly
entities:TEntities
The labelled entity models. Enables easy use of EntityType with typeof
from the root verse instance.
Defined in
packages/verse-core/src/verse.ts:299
from
readonly
from:AsyncFrom
<TEntities
>
Provides access to strongly-typed entity query operations.
Defined in
packages/verse-core/src/verse.ts:283
metadata
readonly
metadata:Metadata
The metadata object containing the configuration, model, and inheritance strategy.
Defined in
packages/verse-core/src/verse.ts:288
Methods
compile()
compile<
R
,A
>(query
: (from
:From
<TEntities
>, ...args
:A
) =>R
): (...args
:A
) =>QueryResult
<R
>
Compiles a query and returns a function that can be invoked to execute the query.
Compiled queries are useful when you need to execute the same query multiple times with different parameters, or when you want to cache the query for reuse. Compiled query execution is faster than non-compiled query execution because the query is only compiled once.
Type Parameters
Type Parameter |
---|
R |
A extends readonly unknown [] |
Parameters
Parameter | Type | Description |
---|---|---|
query | (from : From <TEntities >, ...args : A ) => R | The query function to compile. |
Returns
Function
The compiled query function that can be invoked with the specified arguments.
Parameters
Parameter | Type |
---|---|
...args | A |
Returns
QueryResult
<R
>
Example
const query = db.compile(
(from, $id: number) => from.albums.where(a => a.albumId === $id).single());
const album = query(42);
Defined in
packages/verse-core/src/verse.ts:413
compileUow()
compileUow<
R
,A
>(query
: (from
:From
<TEntities
>, ...args
:A
) =>R
): (uow
:UnitOfWork
<TEntities
>, ...args
:A
) =>QueryResult
<R
>
Compiles a query and returns a function that can be invoked to execute the query within a unit of work. Entity changes made within the unit of work will be tracked and persisted to the database when the unit of work is committed.
Compiled queries are useful when you need to execute the same query multiple times with different parameters, or when you want to cache the query for reuse. Compiled query execution is faster than non-compiled query execution because the query is only compiled once.
Type Parameters
Type Parameter |
---|
R |
A extends readonly unknown [] |
Parameters
Parameter | Type | Description |
---|---|---|
query | (from : From <TEntities >, ...args : A ) => R | The query function to compile. |
Returns
Function
The compiled query function that can be invoked with the specified arguments.
Parameters
Parameter | Type |
---|---|
uow | UnitOfWork <TEntities > |
...args | A |
Returns
QueryResult
<R
>
Example
const query = db.compileUow(
(from, $id: number) => from.albums.where(a => a.albumId === $id).single());
const uow = db.uow();
const album = query(uow, 42);
Defined in
packages/verse-core/src/verse.ts:442
uow()
uow():
UnitOfWork
<TEntities
>
Creates a new unit of work, an object that tracks changes to entities and can be used to persist them to the database.
Returns
UnitOfWork
<TEntities
>
A new unit of work.
Example
const uow = db.uow();
const customer =
await uow.customers
.where(c => c.name === "Customer 1")
.single();
customer.name = "Customer 1 Updated!";
await uow.commit();