todepond-incremementcloudlabcountantispam.web.val.run
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { blob } from "https://esm.town/v/std/blob";
import { sqlite } from "https://esm.town/v/std/sqlite";
// Make SQLite table to store the count increments (with timestamps)
export default async function(req: Request): Promise<Response> {
const result = await sqlite.batch([
"CREATE TABLE IF NOT EXISTS counter_2_baby (timestamp DATETIME DEFAULT CURRENT_TIMESTAMP)",
"INSERT INTO counter_2_baby DEFAULT VALUES",
"SELECT COUNT(*) FROM counter_2_baby",
]);
const bitWeNeed = result[2].rows[0][0];
// const oldCount = await blob.getJSON("lab-count") ?? 0;
const startingValue = 172243 - 211;
const newCount = bitWeNeed + startingValue;
// await blob.setJSON("lab-count", newCount);
return Response.json(newCount);
}
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!
v13
May 23, 2024