Readme

Lowdb Example

This val demonstrates the integration between valtown and lowdb.

Read the Lodash section if you want to give superpowers to your DB.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { extractValInfo } from "https://esm.town/v/pomdtr/extractValInfo";
import { BlobPreset } from "https://esm.town/v/pomdtr/lowdb";
type Data = {
posts: {
id: number;
title: string;
}[];
};
// use the val name as a key ("@pomdtr/testLowDB")
const { slug } = extractValInfo(import.meta.url);
// Read or initialize DB from blob
const db = await BlobPreset<Data>(slug, { posts: [] });
// Edit db content using plain JavaScript (updates are automatically persisted)
await db.update(({ posts }) => posts.push({ id: posts.length + 1, title: "lowdb is awesome" }));
console.log(db.data);
👆 This is a val. Vals are TypeScript snippets of code, written in the browser and run on our servers. Create scheduled functions, email yourself, and persist small pieces of data — all from the browser.