1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { sqlite } from "https://esm.town/v/std/sqlite?v=6";
export const setupSQLiteKV = () => sqlite.execute("create table if not exists kv (key text primary key, value text)");
await setupSQLiteKV();
export async function set(key, value) {
await sqlite.execute({
sql: `insert into kv (key, value) values (?, ?)
on conflict (key) do update set value = ?`,
args: [key, value, value],
});
return "OK";
}
export async function get(key) {
return (await sqlite.execute({
sql: `select value from kv where key = ?`,
args: [key],
})).rows[0][0];
}
const start = performance.now();
console.log(
await set("key", new Date()),
);
console.log("set time: " + (performance.now() - start));
const start2 = performance.now();
console.log(await get("key"));
console.log("get time: " + (performance.now() - start2));
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
June 10, 2024