API Reference / @evolu/common / Evolu/Internal / createEvolu
Function: createEvolu()
function createEvolu(deps): <S>(schema, partialConfig) => Evolu<S>;
Defined in: packages/common/src/Evolu/Evolu.ts:432
Creates an Evolu instance configured with the specified EvoluSchema and optional configuration.
This function returns a configured Evolu instance, providing a typed interface for querying, mutating, and syncing your application's data. The returned instance includes:
- Subscription methods for receiving updates on queries, the owner, errors, and sync state.
- Methods for creating, updating, or deleting rows in a type-safe manner.
- Methods for querying data using Evolu's typed SQL queries, leveraging Kysely under the hood.
- Built-in support for local-first and offline-first data with automatic sync and merging.
- Automatic schema evolution that updates the underlying database with new columns or tables.
- Managing owner data with resetAppOwner and restoreAppOwner.
Example
const TodoId = id("Todo");
type TodoId = InferType<typeof TodoId>;
const TodoCategoryId = id("TodoCategory");
type TodoCategoryId = InferType<typeof TodoCategoryId>;
const NonEmptyString50 = maxLength(50, NonEmptyString);
type NonEmptyString50 = InferType<typeof NonEmptyString50>;
const Schema = {
todo: {
id: TodoId,
title: NonEmptyString1000,
isCompleted: nullOr(SqliteBoolean),
categoryId: nullOr(TodoCategoryId),
},
todoCategory: {
id: TodoCategoryId,
name: NonEmptyString50,
},
};
const evolu = createEvolu(evoluReactDeps)(Schema);
Parameters
Parameter | Type |
---|---|
deps | EvoluDeps |
Returns
<S>(schema, partialConfig): Evolu<S>;
Type Parameters
Type Parameter |
---|
S extends Readonly <Record <string , Readonly <Record <string , Type <any , any , any , any , any , any >>> & object >> |
Parameters
Parameter | Type |
---|---|
schema | S |
partialConfig | Partial <EvoluConfigWithInitialData <S >> |
Returns
Evolu
<S
>