10// update the cache that was saved to blob storage by the /cache route
11export default async function (interval: Interval) {
12 // every page in the "Glancer demo" database should have it's own blob, so we have a cache for each demo
13 // this cron saves a blob for every page in the Demos DB
14 try {
15 // get notion pages with the databaseId
16 const pages = await notion.databases.query({
17 database_id: Deno.env.get("GLANCE_DEMOS_DB_ID"),
18 });
19 // for each page in the demo database, save a blob
20 for (const page of pages.results) {
21 const blobKey = await blobKeyForDemoCache(import.meta.url, page.id);
1import { Hono } from "npm:hono";
2import { getDatabase } from "../../controllers/getDatabase.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);
198```
199โโโ backend/
200โ โโโ database/
201โ โ โโโ migrations.ts # Schema definitions
202โ โ โโโ queries.ts # DB query functions
257 ```
258
259### Database Patterns
260- Run migrations on startup or comment out for performance
261- Change table names when modifying schemas rather than altering
3// Import route modules
4import cobrowse from "./cobrowse.ts";
5import database from "./database.ts";
6import demo from "./demo.ts";
7import page from "./page.ts";
12
13// mount routes
14app.route("/db", database);
15app.route("/page", page);
16app.route("/cobrowse", cobrowse);
1import { Hono } from "https://esm.sh/hono@3.11.7";
2import { runMigrations, seedData } from "./database/migrations.ts";
3import examsRoutes from "./routes/exams.ts";
4import progressRoutes from "./routes/progress.ts";
15});
16
17// Initialize database on startup
18let dbInitialized = false;
19async function initializeDatabase() {
20 if (!dbInitialized) {
21 console.log("Initializing database...");
22 await runMigrations();
23 await seedData();
24 dbInitialized = true;
25 console.log("Database initialized successfully!");
26 }
27}
28
29// Middleware to ensure database is initialized
30app.use("*", async (c, next) => {
31 await initializeDatabase();
32 await next();
33});
5 getUserBookmarks,
6 deleteBookmark
7} from "../database/queries.ts";
8
9const bookmarks = new Hono();
5 getMaterialsBySubject,
6 createStudyMaterial
7} from "../database/queries.ts";
8
9const materials = new Hono();
6 createTestScore,
7 getUserTestScores
8} from "../database/queries.ts";
9
10const progress = new Hono();
6 getMaterialsByExamType,
7 getMaterialsBySubject
8} from "../database/queries.ts";
9
10const exams = new Hono();
1import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";
2
3// Database schema for Tamil Nadu Exam Preparation App
4export async function runMigrations() {
5 console.log("Running database migrations...");
6
7 // Users table
113 `);
114
115 console.log("Database migrations completed successfully!");
116}
117