Your clientside data,
blazingly fast ⚡
// All users called Alice or Charlie
// with an age greater than 24
const items = await many(userTable, {
where: {
name: { in: ['Alice', 'Charlie'] },
age: { gt: 24 }
},
});
Fully typesafe entities. Automatic property inference in queries. BlinkDB is 100% written in Typescript, and automatically prevents issues with incorrect or outdated types.
import { createDB, createTable, insertMany, uuid } from "blinkdb";
import { User } from "./User.ts";
// Set up the table
const db = createDB();
const userTable = createTable<User>(db, "users")();
// Insert the users!
await insertMany(userTable, [
{ id: uuid(), name: "Alice", posts: [{ content: "Hello World! :)" }] },
{ id: uuid(), name: "Bob", age: 24 },
{ id: uuid(), age: 25 } // ERROR: Property 'name' is missing
]);
export interface User {
id: number;
name: string;
age?: number;
posts?: { content: string }[];
};
Filter, sort, and paginate directly in BlinkDB like in any other database. Automatically take advantage of indexes. Use batch & in-place update/remove operations.
// All users called Alice or Charlie
// with an age greater than 24
const items = await many(userTable, {
where: {
name: { in: ['Alice', 'Charlie'] },
age: { gt: 24 }
},
});
// First user in the alphabet
// who's younger than 30yrs
const items = await first(userTable, {
where: {
age: { lt: 30 }
},
sort: {
key: "name",
order: "asc"
}
});
// Just user 10-20 please :)
const items = await many(userTable, {
limit: {
take: 10,
skip: 10
}
});
React to changes in your database as soon as they occur. Keep your UI always up-to-date with the current state.
// React to changes on the userTable
await watch(userTable, { where: { name: "Alice" } }, (aliceUsers) => {
console.log("Users named Alice: ", aliceUsers.length);
});
export const AddEntityButton = () => {
const onButtonClick = () => {
await insert(userTable, { name: "Alice", age: 25 });
};
return (
<button onClick={onButtonClick}>
Click Me
</button>
);
};
Console log