lovadb-sdk
v0.2.0
Published
Client for the LovaDB document API
Readme
lovadb-sdk
Client for the LovaDB document API.
Install
npm install lovadb-sdkUsage
import { init } from "lovadb-sdk";
type Schema = { todos: { title: string; done: boolean } };
const db = init<Schema>({ sandboxId: "abc12345" });
await db.auth.sendCode("[email protected]");
const user = await db.auth.verifyCode("[email protected]", "123456");
console.log(user.email);
const todos = db.collection("todos");
const todo = await todos.create({ title: "Buy milk", done: false });
await todos.update(todo.id, { done: true });
const all = await todos.list({ order: "desc" });
console.log(all.map((t) => `${t.title}: ${t.done}`));
await todos.delete(todo.id);React
import { init } from "lovadb-sdk/react";
const db = init<{ todos: { title: string; done: boolean } }>({
sandboxId: "abc12345",
});
function Todos() {
const { data, isLoading } = db.useQuery("todos", { order: "desc" });
if (isLoading) return <p>Loading…</p>;
return <ul>{data?.map((t) => <li key={t.id}>{t.title}</li>)}</ul>;
}Hooks: useQuery, useAuth, useUsers, usePresence.
MIT licensed.
