Skip to content

Class: ReactiveDatabase<ObjectMap>

The main entry point for the Reactive Active Record ORM.

Type Parameters

Type ParameterDefault typeDescription
ObjectMap extends Record<string, PlainObject>DefaultObjectMapan interface where the key is the name of the store and the value is the type of the object stored in that store.

Constructors

Constructor

ts
new ReactiveDatabase<ObjectMap>(opts: Partial<ReactiveDatabaseOptions<ObjectMap>>, introspector?: ReactiveDatabaseIntrospector<ObjectMap>): ReactiveDatabase<ObjectMap>;

Creates a new ReactiveDatabase instance.

Parameters

ParameterTypeDescription
optsPartial<ReactiveDatabaseOptions<ObjectMap>>The configuration options for the ReactiveDatabase instance.
introspector?ReactiveDatabaseIntrospector<ObjectMap>An optional introspector instance for testing purposes.

Returns

ReactiveDatabase<ObjectMap>

Throws

InvalidReactiveDatabaseOptionsError if the options are invalid.

Throws

ReactiveDatabaseInitializationException if the database cannot be initialized.

Instance Accessors

errorHandler

Get Signature

ts
get errorHandler(): Readonly<ErrorHandler>;

Provides methods for handling asyncronously thrown errors.

WARNING

If an error is thrown and there are not any handlers registered, the error will be thrown normally. Otherwise the error is "swallowed" and will not be thrown by the ReactiveDatabase.

Returns

Readonly<ErrorHandler>


logger

Get Signature

ts
get logger(): Readonly<Logger>;

A logger instance which can be used to subscribe to log events.

Returns

Readonly<Logger>


models

Get Signature

ts
get models(): readonly StringKeyOf<ObjectMap>[];

Provides an array of all the models which have been registered with the ReactiveDatabase.

Returns

readonly StringKeyOf<ObjectMap>[]


promise

Get Signature

ts
get promise(): Promise<void>;

Waits for the database to be ready.

Returns

Promise<void>


ready

Get Signature

ts
get ready(): boolean;

Indicates whether the database is ready to be used.

Returns

boolean

Instance Methods

model()

ts
model<K>(model: K): ReactiveModelConstructor<ObjectMap, ObjectMap[K], { [K in string]: ReactiveDatabaseModelDefinition<ObjectMap[K]> }[K]["primaryKey"]>;

Retrieve a model constructor for the specified model.

Type Parameters

Type ParameterDescription
K extends stringThe name of the model to get.

Parameters

ParameterTypeDescription
modelKThe name of the model to get.

Returns

ReactiveModelConstructor<ObjectMap, ObjectMap[K], { [K in string]: ReactiveDatabaseModelDefinition<ObjectMap[K]> }[K]["primaryKey"]>

The model constructor for the specified model.

Throws

ReactiveDatabaseNoSuchModelException if the model does not exist.


shutdown()

ts
shutdown(): Promise<void>;

Closes the database connection, cleans up resources, and stops all event listeners.

Returns

Promise<void>

Remarks

This method should be called when the database is no longer needed.

Static Methods

shutdown()

ts
static shutdown(): Promise<void>;

Closes all database connections in the current context

Returns

Promise<void>