8โโโ index.ts # Main HTTP entry point (Hono app)
9โโโ backend/
10โ โโโ database/
11โ โโโ cache.ts # Database cache functions
12โโโ test.html # Plant API testing interface
13โโโ admin.html # Cache admin interface
40
41### GET /admin
42Simple admin interface for viewing the cache database. Displays:
43- Total number of cached entries
44- List of all cached plants with their full JSON data
225- Built with Hono framework
226- Uses OpenAI GPT-4o-mini model
227- SQLite database for caching with automatic table creation
228- Includes input validation and error handling
229- Returns structured JSON responses
9<body class="bg-gray-50 p-4">
10 <div class="max-w-4xl mx-auto">
11 <h1 class="text-2xl font-bold mb-4">Cache Database</h1>
12 <a href="/" class="text-blue-600 hover:underline mb-4 inline-block">โ Back to Test Page</a>
13
11 clearCache,
12 type PlantInfo
13} from "./backend/database/cache.ts";
14
15const app = new Hono();
45 example: "/plant/rose",
46 testPage: "/ - Simple testing interface",
47 adminPage: "/admin - Cache database admin interface",
48 cache: {
49 totalCachedPlants: stats.totalEntries,
59});
60
61// Admin page to view cache database
62app.get("/admin", async (c) => {
63 const html = await readFile("/admin.html", import.meta.url);
178});
179
180// Test database endpoint
181app.get("/test-db", async (c) => {
182 try {
183 console.log("Testing database connection...");
184
185 // Test basic SQLite functionality
200
201 return c.json({
202 message: "Database test successful",
203 testResult,
204 selectResult
205 });
206 } catch (error) {
207 console.error("Database test failed:", error);
208 return c.json({
209 error: "Database test failed",
210 details: error instanceof Error ? error.message : "Unknown error"
211 }, 500);
172```
173โโโ backend/
174โ โโโ database/
175โ โ โโโ migrations.ts # Schema definitions
176โ โ โโโ queries.ts # DB query functions
234- Handle API calls properly with proper error catching
235
236### Database Patterns
237- Run migrations on startup or comment out for performance
238- Change table names when modifying schemas rather than altering
189```
190โโโ backend/
191โ โโโ database/
192โ โ โโโ migrations.ts # Schema definitions
193โ โ โโโ queries.ts # DB query functions
248 ```
249
250### Database Patterns
251- Run migrations on startup or comment out for performance
252- Change table names when modifying schemas rather than altering
315
316### SQL Operations
317- **execute-sql** / **sqlite-query**: Execute a SQL query against a SQLite database
318- **execute-sql-batch** / **sqlite-exec**: Execute multiple SQL statements against a SQLite database
319
320## Creating Val Town Projects
97```
98โโโ backend/
99โ โโโ database/
100โ โ โโโ migrations.ts
101โ โ โโโ queries.ts
229#### SQL Operations
23021. **execute-sql** / **sqlite-query**
231 - Description: Execute a SQL query against a SQLite database
232 - Arguments: `statement` (string)
233 - Returns: Query results
234
23522. **execute-sql-batch** / **sqlite-exec**
236 - Description: Execute multiple SQL statements against a SQLite database
237 - Arguments: `statements` (array of strings), Optional: `mode` (string: "read" or "write", default: "read")
238 - Returns: Results of the batch execution
9 server.tool(
10 "execute-sql",
11 "Execute a SQL query against a SQLite database",
12 {
13 statement: z.string().describe("SQL statement to execute"),
36 server.tool(
37 "execute-sql-batch",
38 "Execute multiple SQL statements against a SQLite database",
39 {
40 statements: z.array(z.string()).describe("Array of SQL statements to execute"),
67 server.tool(
68 "sqlite-query",
69 "Execute a SQL query against a SQLite database",
70 {
71 statement: z.string().describe("SQL statement to execute"),
94 server.tool(
95 "sqlite-exec",
96 "Execute multiple SQL statements against a SQLite database",
97 {
98 statements: z.array(z.string()).describe("Array of SQL statements to execute"),
15# healthCheck.ts
16
17This cron runs through all of the databases listed in the Glancer Val's environment variables, queries them, and stores the results in blob storage. The output is JSON rendered as HTML, in an HTTP Val.
18
19We embed that HTTP Val into the Glancer app in Notion. This way, we can see the health of the integration between Notion and val.town from Notion, and it loads instantly, without having to query Notion.
3// Import route modules
4import cobrowse from "./cobrowse.api.routes.ts";
5import database from "./database.api.routes.ts";
6import demo from "./demo.api.routes.ts";
7import page from "./page.api.routes.ts";
12
13// mount routes
14app.route("/db", database);
15app.route("/page", page);
16app.route("/cobrowse", cobrowse);
1import { Hono } from "npm:hono";
2import { getDatabase } from "../../controllers/database.controller.ts";
3
4const app = new Hono();
9 // hit the controller to return data
10 try {
11 const data = await getDatabase(id);
12 //
13 console.log(data);