Skip to content

Commit 2c19220

Browse files
committed
Prereqs installed
1 parent 79dbbf4 commit 2c19220

File tree

5 files changed

+258
-0
lines changed

5 files changed

+258
-0
lines changed

.env.local

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
###########################
2+
# Notion Configuration #
3+
###########################
4+
5+
# Your Notion API integration key (starts with `secret_`)
6+
NOTION_API_KEY=XXXXXXXXXXXXX
7+
8+
# The ID of the Notion database you're querying
9+
NOTION_DATABASE_ID=your_notion_database_id_here
10+
11+
12+
############################
13+
# PostgreSQL Configuration #
14+
############################
15+
16+
PG_HOST=localhost # or your DB host, like amplify_db
17+
PG_PORT=5432
18+
PG_DATABASE=your_database_name
19+
PG_USER=your_db_username
20+
PG_PASSWORD=your_db_password

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# .env.*
2+
/node_modules

index.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { Client } from "@notionhq/client";
2+
import { config } from "dotenv";
3+
import pkg from "pg";
4+
5+
const { Pool } = pkg;
6+
7+
// Load environment variables
8+
config();
9+
10+
// Initialize Notion client
11+
const notion = new Client({ auth: process.env.NOTION_API_KEY });
12+
13+
// Initialize PostgreSQL connection pool
14+
const pool = new Pool({
15+
host: process.env.PG_HOST,
16+
port: process.env.PG_PORT,
17+
database: process.env.PG_DATABASE,
18+
user: process.env.PG_USER,
19+
password: process.env.PG_PASSWORD,
20+
});
21+
22+
(async () => {
23+
try {
24+
const response = await notion.databases.query({
25+
database_id: process.env.NOTION_DATABASE_ID,
26+
});
27+
28+
for (const page of response.results) {
29+
const name = page.properties.Name.title[0]?.plain_text || "Unnamed";
30+
const date = page.properties.Date?.date?.start || null;
31+
32+
if (date) {
33+
await pool.query(
34+
`INSERT INTO notion_table (name, date)
35+
VALUES ($1, $2)
36+
ON CONFLICT (name) DO UPDATE SET date = EXCLUDED.date`,
37+
[name, date]
38+
);
39+
}
40+
}
41+
42+
console.log("Data sync complete.");
43+
} catch (err) {
44+
console.error("Error during sync:", err);
45+
} finally {
46+
await pool.end();
47+
}
48+
})();

package-lock.json

Lines changed: 169 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "map-dashboard",
3+
"version": "1.0.0",
4+
"type": "module",
5+
"description": "<div align=\"center\"> <h1>Map Dashboard Web Application</h1> <p> This repository houses the source code for the Map Dashboard data visualization web application project. It uses <a href=\"https://vuejs.org/\"><strong>Vue 3</strong></a> and <a href=\"https://vuetifyjs.com/en/\"><strong>Vuetify</strong></a>. </p> </div>",
6+
"main": "index.js",
7+
"scripts": {
8+
"test": "echo \"Error: no test specified\" && exit 1",
9+
"start": "node index.js"
10+
},
11+
"keywords": [],
12+
"author": "",
13+
"license": "ISC",
14+
"dependencies": {
15+
"@notionhq/client": "^3.1.1",
16+
"dotenv": "^16.5.0",
17+
"pg": "^8.16.0"
18+
}
19+
}

0 commit comments

Comments
 (0)