-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetupDb.js
More file actions
32 lines (29 loc) · 897 Bytes
/
setupDb.js
File metadata and controls
32 lines (29 loc) · 897 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// file that configures the setups the database tables for the cloud (neon/render)
require('dotenv').config(); // for environment variables
const { Client } = require('pg');
const client = new Client({
connectionString: process.env.DATABASE_URL,
ssl: {rejectUnauthorized: false}
});
async function createTable() {
try {
await client.connect();
// Creamos una tabla simple: ID, Texto original, y fecha
const query = `
CREATE TABLE IF NOT EXISTS analysis_history (
id SERIAL PRIMARY KEY,
original_text TEXT,
word_count INT,
most_common_char CHAR(1),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
`;
await client.query(query);
console.log("Tabla 'analysis_history' creada con éxito!");
} catch (err) {
console.error("Error creando tabla:", err);
} finally {
await client.end();
}
}
createTable();