API reference / @evolu/common / Evolu/Internal / createEvolu
Function: createEvolu()
function createEvolu(deps): <S>(schema, config?) => Evolu<S>;
Defined in: packages/common/src/Evolu/Evolu.ts:510
Creates an Evolu instance for a platform configured with the specified EvoluSchema and optional EvoluConfig providing a typed interface for querying, mutating, and syncing your application's data.
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);
Instance Caching
Evolu caches instances by EvoluConfig name to enable hot reloading and
multitenancy. Multiple calls to createEvolu with the same name return the
same instance, preserving database connections and state across module
reloads during development. This ensures a seamless developer experience
where edits don't interrupt ongoing sync or lose in-memory state.
For testing, either dispose of instances after each test (TODO: implement dispose method) or use unique instance names to ensure proper isolation between test cases.
Parameters
| Parameter | Type |
|---|---|
deps | EvoluDeps |
Returns
<S>(schema, config?): Evolu<S>;
Type Parameters
| Type Parameter |
|---|
S extends Readonly<Record<string, Readonly<Record<string, Type<any, any, any, any, any, any>>>>> |
Parameters
| Parameter | Type |
|---|---|
schema | ValidateSchema<S> extends never ? S : ValidateSchema<S> |
config? | EvoluConfig |
Returns
Evolu<S>