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 {
listSqliteTablesREADME.md1 match
1# listSqliteTables
23Returns a flat array of the names of all tables in your Val Town SQLite database.
45```ts
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
sqliteDumpREADME.md1 match
1# SQLite Dump Util
23A utility function that generates SQL statements to dump the data and schema of tables in a SQLite database.
45## Usage
1### Blob Array
23Create an array as a Database, instantly!
45Just create a new val for your array:
ValTupleStoragemain.tsx1 match
23import { jsonCodec } from "npm:lexicodec";
4import { KeyValuePair, ScanStorageArgs, Tuple, WriteOps } from "npm:tuple-database";
56export class ValTupleStorage {
1Migrated from folder: Database/ValTupleStorage_Example
ValTupleStorageREADME.md1 match
1Migrated from folder: Database/ValTupleStorage
sqliteWriterREADME.md3 matches
1# SQLite QueryWriter
23The QueryWriter class is a utility for generating and executing SQL queries using natural language and OpenAI. It provides a simplified interface for interacting with your Val Town SQLite database and generating SQL queries based on user inputs.
45This val is inspired by [prisma-gpt](https://github.com/aliyeysides/prisma-gpt). PRs welcome! See **Todos** below for some ideas I have.
42Creates a new instance of the QueryWriter class.
4344- `table`: The name of the database table to operate on.
45- `model` (optional): The model to use for generating SQL queries. Defaults to "gpt-3.5-turbo".
46- `apiKey` (optional): An OpenAI API key. Defaults to `Deno.env.get("OPENAI_API_KEY")`.
68- [ ] Edit prompt to allow for more than just `SELECT` queries
69- [ ] Allow a user to add to the system prompt maybe?
70- [ ] Expand usage beyond just Turso SQLite to integrate with other databases
7172Migrated from folder: projects/gptTools/sqliteWriter
add_to_notion_w_ai_webpagemain.tsx19 matches
41function createPrompt(title, description, properties) {
42let prompt =
43"You are processing content into a database. Based on the title of the database, its properties, their types and options, and any existing descriptions, infer appropriate values for the fields:\n";
44prompt += `Database Title: ${title}\n`;
4546if (description) {
47prompt += `Database Description: ${description}\n\n`;
48} else {
49prompt += "\n";
115}
116117async function get_and_save_notion_db_processed_properties(databaseId)
118{
119const response = await notion.databases.retrieve({ database_id: databaseId });
120const db_id = response.id.replaceAll("-", "");
121const processed_properties = processProperties(response);
126}
127128async function get_notion_db_info(databaseId) {
129databaseId = databaseId.replaceAll("-", "");
130let db_info = null;
131try {
132db_info = await blob.getJSON(databaseId);
133if (!db_info) {
134throw new Error("db_info is null or undefined");
135}
136} catch (error) {
137db_info = await get_and_save_notion_db_processed_properties(databaseId);
138}
139console.log(db_info);
142}
143144async function get_and_save_notion_db_info(databaseId) {
145databaseId = databaseId.replaceAll("-", "");
146let db_info = await get_and_save_notion_db_processed_properties(databaseId);
147db_info["zod_schema"] = createZodSchema(db_info["filteredProps"]);
148return db_info;
288}
289290async function addToNotion(databaseId, text) {
291databaseId = databaseId.replaceAll("-", "");
292const properties = await process_text(databaseId, text);
293console.log(properties);
294const response = await notion.pages.create({
295"parent": {
296"type": "database_id",
297"database_id": databaseId,
298},
299"properties": properties,
316<div id="answer">
317<div id="answer-content" hx-get="/clear" hx-trigger="load delay:2s" hx-target="#answer">
318Processed and added to Notion Database
319</div>
320</div>
329<html>
330<head>
331<title>Add To Money Database W/ AI</title>
332<style>
333{`