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 });
7import { examplePDF } from "../../api/servePDF.ts";
8import { getPage } from "../../../controllers/getPage.ts";
9import { getRelatedPagesFromDatabase } from "../../../controllers/getRelatedPagesFromDatabase.ts";
10
11const app = new Hono();
34
35 // get related Glancer content
36 const relatedPages = await getRelatedPagesFromDatabase(id);
37 // console.log("relatedPages: ", relatedPages);
38
1import { Hono } from "npm:hono";
2import { getPage } from "../../controllers/getPage.ts";
3import { getDatabase } from "../../controllers/getDatabase.ts";
4
5const app = new Hono();
12// that blob determines whether or not the cobrowsing button is ON or OFF
13export default async function (interval: Interval) {
14 // every page in the "Glancer demo" database should have it's own blob, so we have a cache for each demo
15 // this cron saves a blob for every page in the Demos DB
16 try {
17 // get notion pages with the databaseId
18 const pages = await notion.databases.query({
19 database_id: Deno.env.get("GLANCE_DEMOS_DB_ID"),
20 });
21 // for each page in the demo database, save a blob
22 for (const page of pages.results) {
23 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);
6});
7
8export async function getRelatedPagesFromDatabase(
9 pageId: string // the /demo page
10) {
11 // get database
12 try {
13 const response = await notion.databases.query({
14 database_id: Deno.env.get("GLANCE_CONTENT_DB_ID"),
15 filter: {
16 property: "Glancer demos", // the property in the Glancer content database that connects to the /demo
17 relation: {
18 contains: pageId, // the Glancer demos property holds the /demo page id to which it is related
7import { examplePDF } from "../../api/servePDF.ts";
8import { getPage } from "../../../controllers/getPage.ts";
9import { getRelatedPagesFromDatabase } from "../../../controllers/getRelatedPagesFromDatabase.ts";
10
11const app = new Hono();
34
35 // get related Glancer content
36 const relatedPages = await getRelatedPagesFromDatabase(id);
37 // console.log("relatedPages: ", relatedPages);
38