luciaValtownSqlitemain.tsx22 matches
6import type {
7Adapter,
8DatabaseSession,
9DatabaseUser,
10RegisteredDatabaseSessionAttributes,
11RegisteredDatabaseUserAttributes,
12} from "npm:lucia";
1323}
2425interface SessionSchema extends RegisteredDatabaseSessionAttributes {
26id: string;
27user_id: string;
29}
3031interface UserSchema extends RegisteredDatabaseUserAttributes {
32id: string;
33}
59public async getSessionAndUser(
60sessionId: string,
61): Promise<[session: DatabaseSession | null, user: DatabaseUser | null]> {
62const [databaseSession, databaseUser] = await Promise.all([
63this.getSession(sessionId),
64this.getUserFromSessionId(sessionId),
65]);
66return [databaseSession, databaseUser];
67}
6869public async getUserSessions(userId: string): Promise<DatabaseSession[]> {
70const result = await this.controller.getAll<SessionSchema>(
71`SELECT * FROM ${this.escapedSessionTableName} WHERE user_id = ?`,
72[userId],
73);
74return result.map((val) => transformIntoDatabaseSession(val));
75}
7677public async setSession(databaseSession: DatabaseSession): Promise<void> {
78const value: SessionSchema = {
79id: databaseSession.id,
80user_id: databaseSession.userId,
81expires_at: Math.floor(databaseSession.expiresAt.getTime() / 1000),
82...databaseSession.attributes,
83};
84const entries = Object.entries(value).filter(([_, v]) => v !== undefined);
108}
109110private async getSession(sessionId: string): Promise<DatabaseSession | null> {
111const result = await this.controller.get<SessionSchema>(
112`SELECT * FROM ${this.escapedSessionTableName} WHERE id = ?`,
114);
115if (!result) return null;
116return transformIntoDatabaseSession(result);
117}
118119private async getUserFromSessionId(sessionId: string): Promise<DatabaseUser | null> {
120const result = await this.controller.get<UserSchema>(
121`SELECT ${this.escapedUserTableName}.* FROM ${this.escapedSessionTableName} INNER JOIN ${this.escapedUserTableName} ON ${this.escapedUserTableName}.id = ${this.escapedSessionTableName}.user_id WHERE ${this.escapedSessionTableName}.id = ?`,
123);
124if (!result) return null;
125return transformIntoDatabaseUser(result);
126}
127}
236}
237238function transformIntoDatabaseSession(raw: SessionSchema): DatabaseSession {
239const { id, user_id: userId, expires_at: expiresAtUnix, ...attributes } = raw;
240return {
246}
247248function transformIntoDatabaseUser(raw: UserSchema): DatabaseUser {
249const { id, ...attributes } = raw;
250return {
lucia_middlewaremain.tsx2 matches
49interface Register {
50Lucia: typeof lucia;
51DatabaseUserAttributes: DatabaseUserAttributes;
52}
53}
5455interface DatabaseUserAttributes {
56github_id: number;
57username: string;
sqliteExplorerAppREADME.md1 match
30- [ ] add triggers to sidebar
31- [ ] add upload from SQL, CSV and JSON
32- [ ] add ability to connect to a non-val town Turso database
33- [x] fix wonky sidebar separator height problem (thanks to @stevekrouse)
34- [x] make result tables scrollable
1# VALL-E
23LLM code generation for vals! Make apps with a frontend, backend, and database.
45It's a bit of work to get this running, but it's worth it.
sqliteExplorerAppREADME.md1 match
30- [ ] add triggers to sidebar
31- [ ] add upload from SQL, CSV and JSON
32- [ ] add ability to connect to a non-val town Turso database
33- [x] fix wonky sidebar separator height problem (thanks to @stevekrouse)
34- [x] make result tables scrollable
lucia_middleware_vanillamain.tsx2 matches
26interface Register {
27Lucia: typeof lucia;
28DatabaseUserAttributes: DatabaseUserAttributes;
29}
30}
3132interface DatabaseUserAttributes {
33username: string;
34}
lucia_demomain.tsx2 matches
26interface Register {
27Lucia: typeof lucia;
28DatabaseUserAttributes: DatabaseUserAttributes;
29}
30}
3132interface DatabaseUserAttributes {
33username: string;
34}
lucia_adapter_basemain.tsx22 matches
1import type {
2Adapter,
3DatabaseSession,
4DatabaseUser,
5RegisteredDatabaseSessionAttributes,
6RegisteredDatabaseUserAttributes,
7} from "npm:lucia";
834public async getSessionAndUser(
35sessionId: string,
36): Promise<[session: DatabaseSession | null, user: DatabaseUser | null]> {
37const [databaseSession, databaseUser] = await Promise.all([
38this.getSession(sessionId),
39this.getUserFromSessionId(sessionId),
40]);
41return [databaseSession, databaseUser];
42}
4344public async getUserSessions(userId: string): Promise<DatabaseSession[]> {
45const result = await this.controller.getAll<SessionSchema>(
46`SELECT * FROM ${this.escapedSessionTableName} WHERE user_id = ?`,
48);
49return result.map((val) => {
50return transformIntoDatabaseSession(val);
51});
52}
5354public async setSession(databaseSession: DatabaseSession): Promise<void> {
55const value: SessionSchema = {
56id: databaseSession.id,
57user_id: databaseSession.userId,
58expires_at: Math.floor(databaseSession.expiresAt.getTime() / 1000),
59...databaseSession.attributes,
60};
61const entries = Object.entries(value).filter(([_, v]) => v !== undefined);
87}
8889private async getSession(sessionId: string): Promise<DatabaseSession | null> {
90const result = await this.controller.get<SessionSchema>(
91`SELECT * FROM ${this.escapedSessionTableName} WHERE id = ?`,
93);
94if (!result) return null;
95return transformIntoDatabaseSession(result);
96}
9798private async getUserFromSessionId(sessionId: string): Promise<DatabaseUser | null> {
99const result = await this.controller.get<UserSchema>(
100`SELECT ${this.escapedUserTableName}.* FROM ${this.escapedSessionTableName} INNER JOIN ${this.escapedUserTableName} ON ${this.escapedUserTableName}.id = ${this.escapedSessionTableName}.user_id WHERE ${this.escapedSessionTableName}.id = ?`,
102);
103if (!result) return null;
104return transformIntoDatabaseUser(result);
105}
106}
117}
118119interface SessionSchema extends RegisteredDatabaseSessionAttributes {
120id: string;
121user_id: string;
123}
124125interface UserSchema extends RegisteredDatabaseUserAttributes {
126id: string;
127}
128129function transformIntoDatabaseSession(raw: SessionSchema): DatabaseSession {
130const { id, user_id: userId, expires_at: expiresAtUnix, ...attributes } = raw;
131return {
137}
138139function transformIntoDatabaseUser(raw: UserSchema): DatabaseUser {
140const { id, ...attributes } = raw;
141return {
5```javascript
6// Example usage:
7const dobby = new Dobby("myDatabase", [
8{ name: "id", type: "INTEGER", primaryKey: true },
9{ name: "name", type: "TEXT", notNull: true },
12]);
1314await dobby.createDatabase();
1516// Insert some sample data
474849// Example of using the new dropDatabase function
50await dropDatabase("myDatabase");
5152```
sqliteExplorerAppREADME.md1 match
30- [ ] add triggers to sidebar
31- [ ] add upload from SQL, CSV and JSON
32- [ ] add ability to connect to a non-val town Turso database
33- [x] fix wonky sidebar separator height problem (thanks to @stevekrouse)
34- [x] make result tables scrollable