35 lines
850 B
JavaScript
35 lines
850 B
JavaScript
require('./config');
|
|
const mariadb = require('mariadb');
|
|
|
|
const pool = mariadb.createPool({
|
|
host: process.env.ESCOLARES_HOST,
|
|
user: process.env.ESCOLARES_USER,
|
|
password: process.env.ESCOLARES_PASSWORD,
|
|
database: process.env.ESCOLARES_DB,
|
|
connectionLimit: 5,
|
|
});
|
|
|
|
const obtenerAlumno = (numeroCuenta) => {
|
|
return pool
|
|
.getConnection()
|
|
.then((conn) => {
|
|
return conn
|
|
.query(`CALL busca_alumno_pcpuma('${numeroCuenta}')`)
|
|
.then((rows) => {
|
|
conn.end();
|
|
return rows[0][0];
|
|
})
|
|
.catch((err) => {
|
|
console.log(err);
|
|
conn.end();
|
|
throw new Error('Hubo un problema con el querry.');
|
|
});
|
|
})
|
|
.catch((err) => {
|
|
console.log(err);
|
|
throw new Error('No se pudo conectar con la db.' + err);
|
|
});
|
|
};
|
|
|
|
module.exports = obtenerAlumno;
|