160
161// ==============================================================================
162// SECTION 2: DATABASE FUNCTIONS
163// ==============================================================================
164
165function createDatabaseFunctions(sqlite, KEY, SCHEMA_VERSION) {
166 return {
167 async initialize() {
203 const SCHEMA_VERSION = 2;
204 const KEY = "geminichat";
205 const db = createDatabaseFunctions(sqlite, KEY, SCHEMA_VERSION);
206 await db.initialize();
207
4 // Ensure Notion API key is set
5 const notionApiKey = Deno.env.get("HYDEPTSA_NOTION_API_TOKEN");
6 const databaseId = Deno.env.get("HYDEPTSA_EVENTS_DB_ID");
7 const datePropertyName = "When";
8
9 if (!notionApiKey || !databaseId) {
10 return new Response("Missing Notion API credentials", { status: 500 });
11 }
17 console.log("calling notion api with time:");
18 console.log(eighteenMonthsAgo.toISOString().split("T")[0]);
19 // Fetch pages from Notion database
20 const response = await fetch(`https://api.notion.com/v1/databases/${databaseId}/query`, {
21 method: "POST",
22 headers: {
51 // Transform Notion pages to iCal format
52 const events = data.results.map(page => {
53 // Adjust these property names to match your specific Notion database
54 const dateProperty = page.properties[datePropertyName];
55
94
95 const systemPrompt = `
96 You are a helpful email assistant. You have access to an instantdb database. When people ask for info you will provide it for
97 them by creating an instantdb query for the server to query the database. Return the query param json string only -- the json object that query is assigned to. Note that the results
98 be rendered into 2 tables, one for goals and one for todos, so and associations will not be displayed, instead you should create a query that uses both tables.
99
100 --------------------------------------------------------------------------
101 Here is an example instantdb query (the examples use an unrelated database):
102
103 Fetch namespace
651 ------------------------------------------------
652
653 Here is the schema of the instantdb database:
654
655 const _schema = i.schema({
17 { name: "Express", icon: "🚂", explanation: "Fast, unopinionated, minimalist web framework for Node.js", complexity: 2 },
18 { name: "Django", icon: "🎸", explanation: "A high-level Python Web framework that encourages rapid development", complexity: 3 },
19 { name: "Ruby on Rails", icon: "🛤️", explanation: "A web-application framework that includes everything needed to create database-backed web applications", complexity: 3 },
20 { name: "Flask", icon: "🧪", explanation: "A lightweight WSGI web application framework in Python", complexity: 2 },
21 ],
22 database: [
23 { name: "PostgreSQL", icon: "🐘", explanation: "A powerful, open source object-relational database system", complexity: 3 },
24 { name: "MongoDB", icon: "🍃", explanation: "A document-oriented NoSQL database used for high volume data storage", complexity: 2 },
25 { name: "MySQL", icon: "🐬", explanation: "An open-source relational database management system", complexity: 2 },
26 { name: "Redis", icon: "🔴", explanation: "An open source, in-memory data structure store, used as a database, cache, and message broker", complexity: 2 },
27 { name: "SQLite", icon: "🗃️", explanation: "A C-language library that implements a small, fast, self-contained SQL database engine", complexity: 1 },
28 ],
29 deployment: [
85 stack.push(techOptions.backend[Math.floor(Math.random() * 3)]);
86 }
87 stack.push(techOptions.database[Math.floor(Math.random() * 3)]);
88 stack.push(techOptions.deployment[Math.floor(Math.random() * 3)]);
89 setRecommendedStack(stack);