aaee_ra3_proy4_node-express/dao/impl/ContinenteDAOImpl.js
Isidoro Nevares Martín 38f5722896 Commit inicial
2026-03-13 13:08:48 +01:00

34 lines
1.1 KiB
JavaScript

const IContinenteDAO = require('../IContinenteDAO');
const pool = require('../../gestores/gestorDB');
const Continente = require('../../models/Continente');
class ContinenteDAOImpl extends IContinenteDAO {
// Listar todos los continentes
async listarTodos() {
const [rows] = await pool.query('SELECT codigo, nombre_continente AS nombre FROM T_CONTINENTE');
return rows.map(r => new Continente(r.codigo, r.nombre));
}
// Buscar por código
async buscarPorCodigo(codigo) {
const [rows] = await pool.query(
'SELECT codigo, nombre_continente AS nombre FROM T_CONTINENTE WHERE codigo = ?',
[codigo]
);
if (rows.length === 0) return null;
const r = rows[0];
return new Continente(r.codigo, r.nombre);
}
// Buscar por nombre
async buscarPorNombre(nombre) {
const [rows] = await pool.query(
'SELECT codigo, nombre_continente AS nombre FROM T_CONTINENTE WHERE nombre_continente LIKE ?',
[`%${nombre}%`]
);
return rows.map(r => new Continente(r.codigo, r.nombre));
}
}
module.exports = ContinenteDAOImpl;