-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.js
More file actions
34 lines (31 loc) · 922 Bytes
/
db.js
File metadata and controls
34 lines (31 loc) · 922 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
33
34
const sql = require('mssql');
const { CONNSQL } = require('./config');
const poolPromise = new sql.ConnectionPool(CONNSQL)
.connect()
.then(pool => {
console.log('✅ Conectado a SQL Server');
return pool;
})
.catch(err => {
console.log('❌ Error de conexión: ', err);
});
const log = async (user, ip, action) => {
try {
const pool = await poolPromise;
await pool.request()
.input('Usuario', sql.VarChar, user)
.input('Accion', sql.VarChar, action)
.input('Ip', sql.VarChar, ip)
.query(`
INSERT INTO Registro (Usuario, Accion, Ip)
VALUES (@Usuario, @Accion, @Ip)
`);
return true;
} catch (err) {
console.error(err);
throw new Error('Error al actualizar log: ' + err.message);
}
};
module.exports = {
sql, poolPromise, log
};