Skip to main content

Class: Verse<TEntities>

The top-level Verse object.

See verse for detailed usage information.

Type Parameters

Type ParameterDefault type
TEntities extends Entitiesany

Constructors

new Verse()

new Verse<TEntities>(config: Config, builder: ModelBuilder<TEntities>): Verse<TEntities>

Creates a new instance.

Parameters

ParameterTypeDescription
configConfigThe configuration object.
builderModelBuilder<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

ParameterTypeDescription
query(from: From<TEntities>, ...args: A) => RThe query function to compile.

Returns

Function

The compiled query function that can be invoked with the specified arguments.

Parameters
ParameterType
...argsA
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

ParameterTypeDescription
query(from: From<TEntities>, ...args: A) => RThe query function to compile.

Returns

Function

The compiled query function that can be invoked with the specified arguments.

Parameters
ParameterType
uowUnitOfWork<TEntities>
...argsA
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();

Defined in

packages/verse-core/src/verse.ts:470