stevensDemogetWeather.ts1 match
130}
131132console.log(`Weather forecast updated in the database.`);
133return summary;
134}
125}
126127console.log(`Calendar events imported into the database.`);
128return events;
129} catch (error) {
stevensDemogenerateFunFacts.ts2 matches
89/**
10* Retrieves previously generated fun facts from the memories database
11* @returns Array of previous fun facts
12*/
4748/**
49* Inserts a fun fact into the memories database
50* @param date Date for the fun fact in ISO format
51* @param factText The fun fact text
stevensDemo.cursorrules2 matches
208```
209โโโ backend/
210โ โโโ database/
211โ โ โโโ migrations.ts # Schema definitions
212โ โ โโโ queries.ts # DB query functions
270- Handle API calls properly with proper error catching
271272### Database Patterns
273- Run migrations on startup or comment out for performance
274- Change table names when modifying schemas rather than altering
ValTownForNotionwebhookAPI15 matches
15const app = new Hono();
1617app.post("/example/database/pages", async (c) => {
18// blob keys map to endpoints for the cron resets
19const blobKey = await c.req.url.replace("https://", "");
20const askingFor = c.req.headers.get("asking_for") || "default"; // val.town or default
2122// capture the database id to store in the blob
23const targetId = c.req.headers.get("target_id");
2425// get the pages in this database
26const databaseChildren = await notion.databases.query({ database_id: targetId });
27// delete all pages to prevent bad actors from leaving naughty rows behi
28for (const [key, child] of databaseChildren.results.entries()) {
29const page = await notion.pages.update({
30page_id: child.id,
33}
3435// get the database
36const database = await notion.databases.retrieve({ database_id: targetId });
37// convert the statuses string in the status property into JSON
38const statuses = JSON.parse(database?.properties?.Statuses?.formula?.expression);
39// get the first item on the list of statuses, to set the status for new pages
40const status = statuses[0];
41// add back pages; fresh start for the next person to add favicons
42const defaults = ["val.town", "notion.com", "hono.dev"].reverse();
43// create new database pages from default object
44for (const item of defaults) {
45const page = await notion.pages.create({
46parent: {
47type: "database_id",
48database_id: targetId,
49},
50properties: {
79});
8081app.post("/example/database/page", async (c) => {
82const payload = await c.req.json();
83const data = await payload?.data;
9192// store webhook data in blob storage for resets
93// capture the database id to store in the blob
94const databaseId = data?.parent?.database_id;
95const blobObject = {
96id: databaseId,
97date: new Date(),
98content: askingFor,
cerebras_coderindex2 matches
1import { generateCode } from "./backend/generate-code";
2import { createTables } from "./database/migrations";
3import { createProject, getCode, getNextVersionNumber, insertVersion } from "./database/queries";
45async function servePublicFile(path: string): Promise<Response> {
stevensDemosetupTelegramChatDb.ts2 matches
1// Script to set up the telegram_chats table in SQLite
2// Run this script manually to create the database table
34export default async function setupTelegramChatDb() {
25`);
2627return "Telegram chat database table created successfully.";
28} catch (error) {
29console.error("Error setting up telegram_chats table:", error);
stevensDemoREADME.md1 match
47- For the Google Calendar integration you'll need `GOOGLE_CALENDAR_ACCOUNT_ID` and `GOOGLE_CALENDAR_CALENDAR_ID`. See [these instuctions](https://www.val.town/v/stevekrouse/pipedream) for details.
4849important caveat: the admin dashboard doesn't have auth! currently it just relies on security by obscurity of people not knowing the url to a private val. this is not very secure, if you put sensitive data in a database you should think carefully about how to secure it.
5051Overall it's a simple enough project that I encourage you to just copy the ideas and run in your own direction rather than try to use it as-is.
stevensDemoREADME.md2 matches
45* `index.ts` - this is the **entrypoint** for this whole project
6* `database/` - this contains the code for interfacing with the app's SQLite database table
78## Hono
26## CRUD API Routes
2728This app has two CRUD API routes: for reading and inserting into the messages table. They both speak JSON, which is standard. They import their functions from `/backend/database/queries.ts`. These routes are called from the React app to refresh and update data.
2930## Errors
stevensDemoREADME.md6 matches
1# Database
23This app uses [Val Town SQLite](https://docs.val.town/std/sqlite/) to manage data. Every Val Town account comes with a free SQLite database, hosted on [Turso](https://turso.tech/). This folder is broken up into two files:
45* `migrations.ts` - code to set up the database tables the app needs
6* `queries.ts` - functions to run queries against those tables, which are imported and used in the main Hono server in `/backend/index.ts`
78## Migrations
910In `backend/database/migrations.ts`, this app creates a new SQLite table `reactHonoStarter_messages` to store messages.
1112This "migration" runs once on every app startup because it's imported in `index.ts`. You can comment this line out for a slight (30ms) performance improvement on cold starts. It's left in so that users who fork this project will have the migration run correctly.
1314SQLite has much more limited support for altering existing tables as compared to other databases. Often it's easier to create new tables with the schema you want, and then copy the data over. Happily LLMs are quite good at those sort of database operations, but please reach out in the [Val Town Discord](https://discord.com/invite/dHv45uN5RY) if you need help.
1516## Queries
1718The queries file is where running the migrations happen in this app. It'd also be reasonable for that to happen in index.ts, or as is said above, for that line to be commented out, and only run when actual changes are made to your database schema.
1920The queries file exports functions to get and write data. It relies on shared types and data imported from the `/shared` directory.