This script is buggy...

Create valimport { setupDatabase } from "https://esm.town/v/stevekrouse/dateme_sqlite" await setupDatabase()
Readme
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { sqlite } from "https://esm.town/v/std/sqlite?v=4";
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
import { getDocs } from "https://esm.town/v/stevekrouse/getSqliteDateMeDocs";
import { thisWebURL } from "https://esm.town/v/stevekrouse/thisWebURL";
export function createTable() {
return sqlite.execute(`
CREATE TABLE IF NOT EXISTS DateMeDocs (
Name TEXT,
Profile TEXT,
Gender TEXT,
InterestedIn TEXT,
Age Integer,
Location TEXT,
Style TEXT,
WantsKids TEXT,
LocationFlexibility TEXT,
Community TEXT,
Contact TEXT,
LastUpdated TEXT,
id TEXT
)
`);
}
const insertSQL = `INSERT INTO DateMeDocs
(Id, Name, Profile, Gender, Age, Contact, LastUpdated, InterestedIn, Location, Style, LocationFlexibility, Community)
VALUES
(:Id, :Name, :Profile, :Gender, :Age, :Contact, :LastUpdated, :InterestedIn, :Location, :Style, :LocationFlexibility, :Community)`;
export default async function() {
let docs = await getDocs();
return Response.json(docs);
}
export async function setupDatabase() {
await createTable();
const docs = await fetchJSON(thisWebURL());
return docs.map(args =>
sqlite.execute({
sql: insertSQL,
args,
})
);
}
👆 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.