Class: ReactiveDatabase<ObjectMap>
The main entry point for the Reactive Active Record ORM.
Type Parameters
Type Parameter | Default type | Description |
---|---|---|
ObjectMap extends Record <string , PlainObject > | DefaultObjectMap | an 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
new ReactiveDatabase<ObjectMap>(opts: Partial<ReactiveDatabaseOptions<ObjectMap>>, introspector?: ReactiveDatabaseIntrospector<ObjectMap>): ReactiveDatabase<ObjectMap>;
Creates a new ReactiveDatabase instance.
Parameters
Parameter | Type | Description |
---|---|---|
opts | Partial <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
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
logger
Get Signature
get logger(): Readonly<Logger>;
A logger instance which can be used to subscribe to log events.
Returns
models
Get Signature
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
get promise(): Promise<void>;
Waits for the database to be ready.
Returns
Promise
<void
>
ready
Get Signature
get ready(): boolean;
Indicates whether the database is ready to be used.
Returns
boolean
Instance Methods
model()
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 Parameter | Description |
---|---|
K extends string | The name of the model to get. |
Parameters
Parameter | Type | Description |
---|---|---|
model | K | The 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()
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()
static shutdown(): Promise<void>;
Closes all database connections in the current context
Returns
Promise
<void
>