working with postgres

This commit is contained in:
counterweight 2025-02-08 17:02:59 +01:00
parent d8a72e5978
commit 1ef39baa57
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C
6 changed files with 186 additions and 9 deletions

View file

@ -7,6 +7,12 @@ const sequelize = require('./database');
const Session = require('./models/Session');
const SessionNpubbed = require('./models/SessionNpubbed');
sequelize.sync().then(() => {
console.log('Database synced');
}).catch(err => {
console.error('Error syncing the database:', err);
});
const app = express();
const port = 3000;
@ -45,6 +51,7 @@ app.post('/api/session-npubbed', async (req, res) => {
console.log("This is the npub: ${npub}");
try {
await SessionNpubbed.create({
sessionNpubbedUuid: uuid.v7(),

View file

@ -1,18 +1,19 @@
const { Sequelize } = require('sequelize');
const dotenv = require('dotenv');
dotenv.config();
const sequelize = new Sequelize({
dialect: 'sqlite',
storage: './data/database.sqlite',
dialect: 'postgres',
host: 'postgres',
port: 5432,
database: process.env.POSTGRES_DB,
username: process.env.POSTGRES_USER,
password: process.env.POSTGRES_PASSWORD,
define: {
timestamps: false,
freezeTableName: true
},
});
sequelize.sync().then(() => {
console.log('Database synced');
}).catch(err => {
console.error('Error syncing the database:', err);
});
module.exports = sequelize;