API reference / @evolu/common / local-first / createEvolu
Function: createEvolu()
function createEvolu(deps): <S>(schema, config?) => Evolu<S>;
Defined in: packages/common/src/local-first/Evolu.ts:534
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
createEvolu caches instances using Instances by EvoluConfig
name to enable hot reloading and prevent database corruption from multiple
connections. For testing, use unique instance names to ensure proper
isolation.
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>