Skip to content

Commit

Permalink
Merge pull request #255 from evoluhq/new-api
Browse files Browse the repository at this point in the history
New API
  • Loading branch information
steida authored Nov 28, 2023
2 parents d6c1db9 + 7e80483 commit e3a2dd9
Show file tree
Hide file tree
Showing 72 changed files with 4,576 additions and 3,831 deletions.
45 changes: 45 additions & 0 deletions .changeset/blue-tables-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
"eslint-config-evolu": major
"@evolu/common-react": major
"@evolu/react-native": major
"@evolu/common-web": major
"@evolu/common": major
"@evolu/server": major
"native": major
"server": major
"web": major
"@evolu/react": minor
---

New API

With the upcoming React 19 `use` Hook, I took a chance to review and improve the Evolu API. I moved as many logic and types as possible to the Evolu interface to make platform variants more lightweight and to allow the use of Evolu directly out of any UI library.

The most significant change is the split of SQL query declaration and usage. The rest of the API is almost the same except for minor improvements.

### Example

```ts
// Create queries.
const allTodos = evolu.createQuery((db) => db.selectFrom("todo").selectAll());
const todoById = (id: TodoId) =>
evolu.createQuery((db) =>
db.selectFrom("todo").selectAll().where("id", "=", id),
);

// We can load a query or many queries.
const allTodosPromise = evolu.loadQuery(allTodos).then(({ rows }) => {
console.log(rows);
});
evolu.loadQueries([allTodos, todoById(1)]);

// useQuery can load once or use a promise.
const { rows } = useQuery(allTodos);
const { rows } = useQuery(allTodos, { once: true });
const { rows } = useQuery(allTodos, { promise: allTodosPromise });
const { row } = useQuery(todoById(1));
```

I also refactored (read: simplified a lot) Effect Layer usage across all libraries.

There is no breaking change in data storage or protocol.
4 changes: 3 additions & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"updateInternalDependencies": "patch",
"ignore": [],
"___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH": {
"useCalculatedVersionForSnapshots": true,
"onlyUpdatePeerDependentsWhenOutOfRange": true
},
"snapshot": {
"useCalculatedVersion": true
}
}
4 changes: 3 additions & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
{}
{
"plugins": ["./node_modules/prettier-plugin-jsdoc/dist/index.js"]
}
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,20 @@ Client-server architecture provides us with easy backup and synchronization, but
To start using Evolu, define tables for your database and export React Hooks.

```ts
import * as Schema from "@effect/schema/Schema";
import * as S from "@effect/schema/Schema";
import * as Evolu from "@evolu/react";

const TodoId = Evolu.id("Todo");
type TodoId = Schema.Schema.To<typeof TodoId>;
type TodoId = S.Schema.To<typeof TodoId>;

const TodoTable = Schema.struct({
const TodoTable = S.struct({
id: TodoId,
title: Evolu.NonEmptyString1000,
isCompleted: Evolu.SqliteBoolean,
});
type TodoTable = Schema.Schema.To<typeof TodoTable>;
type TodoTable = S.Schema.To<typeof TodoTable>;

const Database = Schema.struct({
const Database = S.struct({
todo: TodoTable,
});

Expand All @@ -59,10 +59,10 @@ export const {
Learn more about [Schema](https://github.com/effect-ts/schema).

```ts
import * as Schema from "@effect/schema/Schema";
import * as S from "@effect/schema/Schema";
import * as Evolu from "@evolu/react";

Schema.parse(Evolu.String1000)(title);
S.parse(Evolu.String1000)(title);
```

### Mutate Data
Expand Down
Loading

1 comment on commit e3a2dd9

@vercel
Copy link

@vercel vercel bot commented on e3a2dd9 Nov 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

evolu – ./

evolu-git-main-evolu.vercel.app
evolu-evolu.vercel.app
evolu.vercel.app
evolu.dev
www.evolu.dev

Please sign in to comment.