6});
7
8export async function getDatabase(id: string) {
9 // get database
10 try {
11 const database = await notion.databases.retrieve({
12 database_id: id,
13 });
14 return database;
15 } catch (error: any) {
16 return {
7
8export async function getAllInteractionsPages() {
9 const databaseId = Deno.env.get("GLANCE_INTERACTIONS_DB_ID");
10
11 if (!databaseId) {
12 throw new Error(
13 "GLANCE_INTERACTIONS_DB_ID environment variable is not set"
16
17 try {
18 const response = await notion.databases.query({
19 database_id: databaseId,
20 });
21
37
38export async function getAllInteractionsPagesWithPagination() {
39 const databaseId = Deno.env.get("GLANCE_INTERACTIONS_DB_ID");
40
41 if (!databaseId) {
42 throw new Error(
43 "GLANCE_INTERACTIONS_DB_ID environment variable is not set"
51
52 while (hasMore) {
53 const response = await notion.databases.query({
54 database_id: databaseId,
55 start_cursor: startCursor,
56 });
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();