Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Readme

Lucia Adapter for val.town

Usage

import { ValTownAdapter } from "https://esm.town/v/pomdtr/lucia_adapter"; import { Lucia } from "npm:lucia@3.0.1"; const adapter = new ValTownAdapter({ user: "user", session: "session", }); const lucia = new Lucia(adapter)
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
import { SQLiteAdapter } from "https://esm.town/v/pomdtr/lucia_adapter_base";
import type { Controller, TableNames } from "https://esm.town/v/pomdtr/lucia_adapter_base";
import { sqlite } from "https://esm.town/v/std/sqlite";
import { zip } from "npm:lodash-es";
export class ValTownAdapter extends SQLiteAdapter {
constructor(tableNames: TableNames) {
super(new ValtownController(), tableNames);
}
}
class ValtownController implements Controller {
constructor() {}
public async get<T>(sql: string, args: any[]): Promise<T | null> {
const result = await sqlite.execute({
sql,
args,
});
return Object.fromEntries(zip(result.columns, result.rows.at(0))) as T;
}
public async getAll<T>(sql: string, args: any[]): Promise<T[]> {
const result = await sqlite.execute({
sql,
args,
});
return result.rows.map(row => Object.fromEntries(zip(result.columns, row))) as T[];
}
public async execute(sql: string, args: any[]): Promise<void> {
await sqlite.execute({
sql,
args,
});
}
}
March 5, 2024