@elribonazo/ridb • Docs
RIDB is a storage agnostic secure database wrapper for the web, written in rust. The project started after years of experience working with web projects in both browser and nodejs platforms, the project was born with some rules / objectives:
- Strong types + proper validation
- Declarative schemas & documents
- Configurable storages, inMemory, monogoDB, sqlite, indexdb
- Secure encryption
- Work seamlessly in browsers or nodejs applications.
The inMemory storage is used by default and is currently supporting the following features:
- Schemas: Creation of declararive schemas with required fields
- Schemas: Implement validation across all the flows extracting properties and required fields when needed
- Schemas: Manage Primary keys
- Internal Storage: write operation, create, update, fetch one, remove, find and count
- Internal Storage: Rust inMemory implementation
- Database default InMemory plugged in
npm:
npm i @elribonazo/ridb --save
yarn:
yarn add @elribonazo/ridb
In CommonJS Modules:
const {
RIDB,
SchemaFieldType
} = require('@elribonazo/ridb');
(async () => {
const db = new RIDB({
demo: {
version: 0,
primaryKey: 'id',
type: SchemaFieldType.object,
properties: {
id: {
type: SchemaFieldType.string,
maxLength: 60
}
}
}
});
console.log("Starting the database");
await db.start();
console.log("Ok :)");
})()
In ES Modules, TypeScript, etc:
import {
RIDB,
SchemaFieldType
} from '@elribonazo/ridb';
(async () => {
const db = new RIDB({
demo: {
version: 0,
primaryKey: 'id',
type: SchemaFieldType.object,
properties: {
id: {
type: SchemaFieldType.string,
maxLength: 60
}
}
}
});
console.log("Starting the database");
await db.start();
console.log("Ok :)");
})()
cd ts
npm i
npm run test
Build requirements:
cd ts
npm i
npm run build
For now, we have enabled the implementation of the whole wasm + javascript integration. In order to run it, write the following:
cd ts
npm i
npm run test
A valid storage must extend BaseStorage class here's some example:
export class InMemory<T extends SchemaType> extends BaseStorage<T> {
async write(operation:Operation<T>): Promise<Doc<T>> {
if (operation.opType === OpType.CREATE) {
return operation.data;
}
throw new Error("Method not implemented.");
}
query(): Promise<void> {
throw new Error("Method not implemented.");
}
findDocumentById(id: string): Promise<null> {
throw new Error("Method not implemented.");
}
count(): Promise<number> {
throw new Error("Method not implemented.");
}
close(): Promise<void> {
throw new Error("Method not implemented.");
}
}