Public
Script
Forked from stevekrouse/dateme_sqlite
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,
})
);
}
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 18, 2024