https://github.com/jeanfredrik/evig
https://github.com/jeanfredrik/evig
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/jeanfredrik/evig
- Owner: jeanfredrik
- Created: 2024-11-17T19:19:42.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-12-17T18:21:40.000Z (6 months ago)
- Last Synced: 2025-01-28T19:23:24.697Z (5 months ago)
- Language: TypeScript
- Size: 177 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Evig
A persistent document database that emits JSON patches.
## API
### `createCollection()`
```ts
import { createClient } from 'redis';
import { createCollection } from 'evig';const redis = createClient({ url: 'redis://127.0.0.1:6379' });
await redis.connect();const usersCollection = await createCollection('users', { redis });
usersCollection.on('patches', (patches) => {
console.log(patches);
});await usersCollection.insert({ id: '123', name: 'Alice' });
// Console: [{ op: 'add', path: '123', value: { id: '123', name: 'Alice' } }]await usersCollection.insert({ id: '456', name: 'Bob' });
// Console: [{ op: 'add', path: '456', value: { id: '456', name: 'Bob' } }]const alice = usersCollection.get('123');
```### `createView()`
```ts
const aliceView = await createView(usersCollection, {
filter: (doc) => doc.name === 'Alice',
});console.log(aliceView.snapshot);
// Console: { '123': { id: '123', name: 'Alice' } }
```