1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// This val demonstrates how to use Kysely with Val Town's SQLite database.
// It uses the VtDialect from @easrng/kyselyVtDialect to connect to the database,
// and types from @nbbaier/kyselyVtTypes to provide type safety.
// The val performs a simple query to select all columns from the 'users' table
// where the id is '1'.
import { VtDialect } from "https://esm.town/v/easrng/kyselyVtDialect";
import type { DB } from "https://nbbaier-kyselyVtTypes.web.val.run/?tables=users";
import { Kysely } from "npm:kysely@0.27.3";
export default async function main(req: Request): Promise<Response> {
const db = new Kysely<DB>({
dialect: new VtDialect(),
});
const rows = await db.selectFrom("users").selectAll().where("id", "=", "1").execute();
return Response.json({
description: "This val demonstrates using Kysely with Val Town's SQLite database.",
query: "SELECT * FROM users WHERE id = '1'",
result: rows
});
}
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!
August 7, 2024