Val Town Code SearchReturn to Val Town

API Access

You can access search results via JSON API by adding format=json to your query:

https://codesearch.val.run/?q=database&page=1&format=json

For typeahead suggestions, use the /typeahead endpoint:

https://codesearch.val.run/typeahead?q=database

Returns an array of strings in format "username" or "username/projectName"

Found 10131 results for "database"(924ms)

84
85### **Service Layer** (External Integrations)
86- Handles external API calls (Notion, databases)
87- Manages data persistence
88- Returns structured results with success/error information
108- `GET /glimpse/login` - User-specific login redirect
109 - Requires user authentication (Google OAuth via LastLogin)
110 - Looks up authenticated user's email in `GLANCE_DEMOS_DB_ID` database
111 - If user found: Redirects to user's personal path (from Path property)
112 - If user not found: Creates new user record and redirects to `/glimpse/thanks`
113 - Shows detailed error information for debugging database structure issues
114
115- `GET /glimpse/thanks` - New user welcome page
213
2141. **Authentication**: User must be authenticated via Google OAuth (handled by LastLogin)
2152. **Database Lookup**: System queries `GLANCE_DEMOS_DB_ID` database for user's email
2163. **User Creation**: If not found, creates new user record with email address
2174. **Welcome Page**: Redirects to `/glimpse/thanks` with next steps information
2196. **User Return**: User can return to `/glimpse/login` once URL is configured
220
221### Database Requirements for Login
222
223The `GLANCE_DEMOS_DB_ID` database must contain:
224- **Email property**: Contains user's email address (exact match with authenticated email)
225- **Path property**: Contains user's redirect path in format `/glimpse/:id` (optional for new users)
231The login endpoint provides detailed error information for debugging:
232- Missing environment variables
233- Database query failures
234- User creation failures (falls back to access denied page)
235- Invalid or missing Path properties
2732. Retrieves page properties to extract Assigned and Viewing properties
2743. **Checks if Viewing property is true** - if not, skips assignment and logs result
2754. Queries `GLANCE_AGENTS_DB_ID` database for agents with matching Assigned property
2765. **STEP 1: Clear Current Demo Blob** - Immediately clears the agent blob for this demo
2776. **STEP 2: Find New Agents** - Queries agents database by Assigned property
2787. **STEP 3: Collect Agent Data** - Fetches complete agent information and validates
2798. **STEP 4: Clear Agents from Other Demo Blobs** - Removes agents from any other demo blobs to prevent double-assignment
283- **Immediate Updates**: Agent blob is updated immediately for fast frontend response
284- **Multi-Blob Clearing**: Ensures agents only appear in one demo blob at a time
285- **Eventual Consistency**: Cron jobs handle Notion database cleanup in the background
286- **No Manual Unassignment**: Assignments are cleared automatically when `Viewing = false`
287- **Reliable**: Blob operations are simpler and more reliable than complex relation management
325- Page must have a **Viewing property set to true** (assignment only occurs for actively viewed pages)
326- Page must have an Assigned property with assigned person
327- Agents database must have pages with Assigned properties matching the assigned person
328- Original page must have a "Glimpse agents" relation property
329- Agent pages must have a "Glimpse demos" relation property
394
395**Performance Benefits:**
396- **Fast Execution**: Blob scanning is faster than database queries
397- **Targeted Processing**: Only processes pages with empty agent arrays
398- **Resource Efficient**: Minimal API calls to Notion
433
434Configure these environment variables for full functionality:
435- `GLANCE_DEMOS_DB_ID` - Notion database ID for demos
436- `GLANCE_CONTENT_DB_ID` - Notion database ID for content
437- `GLANCE_INTERACTIONS_DB_ID` - Notion database ID for interactions
438- `GLANCE_AGENTS_DB_ID` - Notion database ID for agents
439- `NOTION_API_KEY` - Notion API key for database access
440- `NOTION_WEBHOOK_SECRET` - Secret key for webhook authentication
441
452### **Blob Storage + Notion Sync**
453- **Fast blob updates**: Page viewing status stored in Val Town blob storage for instant response (~100ms)
454- **Immediate Notion sync**: When users start viewing pages, Notion database is updated immediately
455- **Automatic cleanup**: Cron job runs every minute to mark stale sessions (>1 minute old) as not viewing
456
517- **Content**: Must exactly match the authenticated user's email address
518
519### **Notion Database Schema**
520Pages in your Notion databases should include these properties for viewing analytics:
521- **Email** (Email or Rich Text) - **Required** for authorization
522- **Session start** (Date) - **Primary viewing status**: Currently viewing + when session began

vt-sqlite-drizzlemigrations.ts1 match

@nbbaierโ€ขUpdated 15 hours ago
3
4export async function createTables() {
5 // Uncomment to reset database
6 await db.run(sql`DROP TABLE IF EXISTS messages`);
7 // Create messages table
13 }
14
15 // Get the Glance Demos database ID from environment
16 const databaseId = Deno.env.get("GLANCE_DEMOS_DB_ID");
17
18 if (!databaseId) {
19 return c.json({
20 error: "Database configuration missing",
21 details: "GLANCE_DEMOS_DB_ID environment variable not set",
22 userEmail: userEmail,
25
26 try {
27 // Find user by email in the database
28 const result = await findUserByEmail(databaseId, userEmail);
29
30 if (!result.success) {
31 return c.json({
32 error: "Failed to query user database",
33 details: result.error,
34 userEmail: userEmail,
35 databaseId: databaseId,
36 }, 500);
37 }
42 console.log(`Creating new user record for: ${userEmail}`);
43
44 const createResult = await createUserRecord(databaseId, userEmail);
45
46 if (!createResult.success) {
181 details: error.message,
182 userEmail: userEmail,
183 databaseId: databaseId,
184 }, 500);
185 }

cerebras_codermain.tsx2 matches

@rrosttโ€ขUpdated 1 day ago
1import { serveFile } from "https://esm.town/v/std/utils/index.ts";
2import { generateCode } from "./backend/generate-code.ts";
3import { createTables } from "./database/migrations.ts";
4import {
5 createProject,
7 getNextVersionNumber,
8 insertVersion,
9} from "./database/queries.ts";
10
11await createTables();

krazyy-cam-configmain.ts2 matches

@krazyykrunalโ€ขUpdated 1 day ago
90 // ---- Query Firestore publicLenses ----
91 const pubDocRes = await fetch(
92 `https://firestore.googleapis.com/v1/projects/${projectId}/databases/(default)/documents/publicLenses/${id}`,
93 { headers: { Authorization: `Bearer ${access_token}` } },
94 );
106 // ---- Query Firestore private user doc ----
107 const privDocRes = await fetch(
108 `https://firestore.googleapis.com/v1/projects/${projectId}/databases/(default)/documents/users/${owner}/lenses/${id}`,
109 { headers: { Authorization: `Bearer ${access_token}` } },
110 );

postherousimages.ts2 matches

@paulkinlanโ€ขUpdated 1 day ago
1import { blob } from "https://esm.town/v/std/blob";
2import { createImage, generateUniqueImageFilename, getImageByFilename, deleteImage } from "../database/queries.ts";
3import { BlogImage, CreateImageData, EmailAttachment } from "../../shared/types.ts";
4
185 await blob.delete(imageRecord.blob_key);
186
187 // Delete from database
188 return await deleteImage(filename);
189}

postherousindex.ts4 matches

@paulkinlanโ€ขUpdated 1 day ago
20 getAllConfig,
21 updateConfigValue,
22} from "./database/queries.ts";
23import { initializeDatabase } from "./database/schema.ts";
24import { processInboxActivity } from "./services/activitypub-inbox.ts";
25import { generateActorDocument } from "./services/activitypub.ts";
48});
49
50// Initialize database lazily on first request to avoid startup memory issues
51let dbInitialized = false;
52async function ensureDbInitialized() {
53 if (!dbInitialized) {
54 await initializeDatabase();
55 dbInitialized = true;
56 }

Townie-Al2TODOs.md1 match

@prubeandoAlโ€ขUpdated 1 day ago
9- [ ] make it one click to branch off like old jp townie demos
10- [ ] opentownie as a pr bot
11- [ ] give it the ability to see its own client-side and server-side logs by building a middleware that shoves them into a SQL light database date and then give it a tool to access them
12- [ ] do a browser use or screenshot thing to give it access to its own visual output
13- [ ] Have it default to creating a new branch off main

Townie-Al2think.ts1 match

@prubeandoAlโ€ขUpdated 1 day ago
7export const thinkTool = tool({
8 description:
9 "Use the tool to think about something. It will not obtain new information or change the database, but just append the thought to the log. Use it when complex reasoning or some cache memory is needed.",
10 parameters: z.object({
11 thought: z.string().describe("A thought to think about."),

Townie-Al2system_prompt.txt2 matches

@prubeandoAlโ€ขUpdated 1 day ago
175```
176โ”œโ”€โ”€ backend/
177โ”‚ โ”œโ”€โ”€ database/
178โ”‚ โ”‚ โ”œโ”€โ”€ migrations.ts # Schema definitions
179โ”‚ โ”‚ โ”œโ”€โ”€ queries.ts # DB query functions
233```
234
235### Database Patterns
236- Run migrations on startup or comment out for performance
237- Change table names when modifying schemas rather than altering

customer-database-setup2 file matches

@stevenvapiโ€ขUpdated 2 months ago

prDatabase

@pdwโ€ขUpdated 2 months ago