Skip to content

Function: initializeReActiveDatabase()

ts
function initializeReActiveDatabase(
  configuration: Partial<VueReActiveDatabaseOptions>,
): Promise<void>;

Initializes the Vue ReActiveRecord plugin with the provided configuration and waits for the real database to be ready.

Parameters

ParameterTypeDescription
configurationPartial<VueReActiveDatabaseOptions>Partial database configuration options to initialize the plugin with. This can include models, schema, and relationships.

Returns

Promise<void>

A promise that resolves when the real database is ready for use.

Remarks

This function is the recommended entry point for programmatically initializing the plugin in browser environments. It ensures that the plugin is fully initialized and the real database is ready before proceeding, which is especially useful for SSR hydration, testing, or advanced scenarios where you need to guarantee database readiness before running queries or mutations.

  • In SSR or if the database is already ready, this resolves immediately.
  • In a browser context, this triggers the plugin's initialization and waits for the real database to be loaded.

Example

typescript
import {
  initializeReActiveDatabase,
  useReActiveModel,
} from "@nhtio/vue-re-active-record";

// Initialize the plugin and wait for the real database to be ready
await initializeReActiveDatabase({
  models: {
    user: {
      schema: "++id, name, email",
      primaryKey: "id",
    },
  },
});

// Now you can safely run queries
const users = await useReActiveModel("user").all();

See