Skip to content

Commit

Permalink
Database connection
Browse files Browse the repository at this point in the history
  • Loading branch information
Sinan-96 committed Sep 16, 2024
1 parent 154a3c9 commit bc34a65
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions app/db.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import pkg from "pg";
import dotenv from "dotenv";

dotenv.config();

const { Client } = pkg;

// Database connection details
const client = new Client({ connectionString: process.env.DATABASE_URL });
const client = new Client({host:"sbu-incstats-nea-psql.postgres.database.azure.com", user:"pmbetaling", password:process.env.DATABASE_PASSWORD, database:"postgres", port:5432});

client
.connect()
Expand All @@ -25,6 +26,7 @@ client
);
}


export function addCategory(category_name) {
return client.query(
`INSERT INTO categories (category_name)
Expand Down Expand Up @@ -110,7 +112,7 @@ export async function getIncNumberByWeek(numberOfDaysAgo) {

export async function getCategoriesArray() {
try {
const result = await client.query("SELECT category_name FROM categories");
const result = await client.query("SELECT name FROM categories");
const categories = result.rows.map(row => row.category_name);
console.log("categories", categories);
return categories;
Expand Down
2 changes: 1 addition & 1 deletion app/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const app = new App({
}),
});

const categories = await getCategoriesArray();
const categories = await getCategoriesArray() ?? [];

app.command('/addcategory', async ({ command, ack, respond }) => {
await ack(); // Acknowledge the command
Expand Down

0 comments on commit bc34a65

Please sign in to comment.