The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as Lambda from "@alchemy.run/aws/Lambda"; |
| 2 | import * as Drizzle from "@alchemy.run/drizzle/LibSQL"; |
| 3 | import * as SQL from "@alchemy.run/sql/SQLite"; |
| 4 | import * as Turso from "@alchemy.run/turso"; |
| 5 | import { sql as drizzleSql } from "drizzle-orm"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | import * as HttpServerResponse from "effect/http/HttpServerResponse"; |
| 8 | import { LambdaDb } from "./resources.ts"; |
| 9 | |
| 10 | export default class TursoLambda extends Lambda.Function<TursoLambda>()( |
| 11 | "TursoLambda", |
| 12 | { |
| 13 | main: import.meta.url, |
| 14 | functionUrl: true, |
| 15 | // @libsql/client loads a native binary in Node; install it for Linux. |
| 16 | build: { install: ["@libsql/client"] }, |
| 17 | }, |
| 18 | Effect.gen(function* () { |
| 19 | const conn = yield* Turso.Connect(LambdaDb); |
| 20 | const sql = yield* SQL.LibSQL(conn); |
| 21 | const db = yield* Drizzle.LibSQL(conn); |
| 22 | return { |
| 23 | fetch: Effect.gen(function* () { |
| 24 | const [row] = yield* sql<{ answer: number }>`SELECT 41 + 1 AS answer`; |
| 25 | const [viaDrizzle] = yield* db.all<{ two: number }>(drizzleSql`SELECT 2 AS two`); |
| 26 | return yield* HttpServerResponse.json({ answer: row?.answer, two: viaDrizzle?.two }); |
| 27 | }).pipe(Effect.orDie), |
| 28 | }; |
| 29 | }).pipe(Effect.provide(Turso.ConnectHttp)), |
| 30 | ) {} |