Documentation
RIDB is a secure light-weight and dependency free database wrapper for the web.
Quick Start
RIDB is a next-gen database storage solution, built in Rust/Typescript and supporting all major storage backends + plugin engine
Schema Definition
import { SchemaFieldType } from '@trust0/ridb'const users = {version: 0 as const,primaryKey: 'id',type: SchemaFieldType.object,properties: {id: {type: SchemaFieldType.string,maxLength: 60}}} as constconst schemas = {users: users}type DatabaseSchemas = typeof schemas;
Define your database schemas with TypeScript for better inference
React Component
const MyComponent: React.FC = () => {const db = useRIDB<DatabaseSchemas>();const [isDbReady, setIsDbReady] = React.useState(false);React.useEffect(() => {if (!isDbReady) {db.start().then(() => {setIsDbReady(true);}).catch((err) => {console.error(err);});}}, [isDbReady]);if (!db) {return <div>No database available</div>;}if (!isDbReady) {return <div>Loading...</div>;}return (<div> <h1>My Component</h1> </div>);};
Create your React component using the useRIDB hook
Wrapper Component
import React from 'react'import { RIDBDatabase, useRIDB } from '@trust0/ridb-react'<RIDBDatabase dbName="myDB" schemas={schemas}><MyComponent /></RIDBDatabase>
Wrap your component with the RIDBDatabase provider