2import { readFile, servePublicFile } from "https://esm.town/v/stevekrouse/utils@187-main/serve-public/index.ts";
3import { Hono } from "npm:hono";
4import { getMessages, insertMessage } from "./database/queries.ts";
5
6const app = new Hono();
465 const KEY = "helloWorldGreeting";
466
467 // Initialize Database
468 await sqlite.execute(`
469 CREATE TABLE IF NOT EXISTS ${KEY}_users (
25## CRUD API Routes
26
27This 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.
28
29## Errors
17
18 However, you should know that SQLite has much more limited
19 support for altering existing tables as compared to other databases.
20 Often it's easier to create new tables with the schema you want, and then
21 copy the data over. */
3import { createTables, tableName } from "./migrations.ts";
4
5// This will create the database table if it doesn't exist.
6// This will run every time the app starts up. You can
7// comment out this line for a modest (30ms) perforamnce improvement
8// on cold starts. It's left in to ensure the database tables are
9// automatically set up correctly for users who fork this app.
10await createTables();
99 try {
100 await sqlite.execute(`DELETE FROM ${tableName}`);
101 console.log("All reviews successfully cleared from the database.");
102 } catch (error) {
103 console.error("Error clearing reviews:", error);
104 throw new Error("Failed to clear reviews from the database.");
105 }
106}
2import { readFile, servePublicFile } from "https://esm.town/v/stevekrouse/utils@187-main/serve-public/index.ts";
3import { Hono } from "npm:hono";
4import { analyzeReviews, clearReviews, getReviews, insertReview } from "./database/queries.ts";
5
6const app = new Hono();
1import { generateCode } from "./backend/generate-code";
2import { createTables } from "./database/migrations";
3import { createProject, getCode, getNextVersionNumber, insertVersion } from "./database/queries";
4
5async function servePublicFile(path: string): Promise<Response> {
1import { generateCode } from "./backend/generate-code";
2import { createTables } from "./database/migrations";
3import { createProject, getCode, getNextVersionNumber, insertVersion } from "./database/queries";
4
5async function servePublicFile(path: string): Promise<Response> {
1import { generateCode } from "./backend/generate-code";
2import { createTables } from "./database/migrations";
3import { createProject, getCode, getNextVersionNumber, insertVersion } from "./database/queries";
4
5async function servePublicFile(path: string): Promise<Response> {
347 // If using sitename parameter, fetch from Neocities API
348 if (sitename) {
349 // Create the database key using sitename.neocities.org format
350 const dbKey = `${sitename}.neocities.org`;
351
353 const neocitiesData = await fetchNeocitiesStats(sitename);
354
355 // Get the current count from database (either fresh or cached)
356 const count = await getCount(dbKey);
357
358 // If API fetch successful, update the database
359 if (neocitiesData && neocitiesData.result === "success") {
360 // Extract the hits value
361 const hits = neocitiesData.info.hits || 0;
362
363 // Store the value in our database for tracking
364 await setCount(dbKey, hits);
365 } else {