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
import { createVal } from "https://esm.town/v/nbbaier/createVal";
import { updateValByName } from "https://esm.town/v/nbbaier/updateValByName";
import { extractValInfo } from "https://esm.town/v/pomdtr/extractValInfo?v=26";
import { fetchText } from "https://esm.town/v/stevekrouse/fetchText?v=6";
async function generateKyselyTypes(tables: string[]): Promise<string> {
const { author } = await extractValInfo(import.meta.url);
try {
const types = await fetchText(
`https://${author}-kyselyVtTypes.web.val.run/?allowTables=true&tables=${tables.map(t => t.trim()).join(",")}`,
);
return types;
}
catch (error) {
console.log(error);
}
}
export async function createKyselyTypesVal(
tables: string[],
name: string,
) {
const code = await generateKyselyTypes(tables);
return await updateValByName({ token: Deno.env.get("valtown"), code, name });
}
console.log(await createKyselyTypesVal(["users"], "db"));
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!
April 1, 2024