-
-
Save parzibyte/3760ff536d29bffb3c3a92fdd650d45d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const conexion = require("../conexion") | |
module.exports = { | |
async insertar(nombre, precio) { | |
let resultados = await conexion.query(`insert into productos | |
(nombre, precio) | |
values | |
($1, $2)`, [nombre, precio]); | |
return resultados; | |
}, | |
async obtener() { | |
const resultados = await conexion.query("select id, nombre, precio from productos"); | |
return resultados.rows; | |
}, | |
async obtenerPorId(id) { | |
const resultados = await conexion.query(`select id, nombre, precio from productos where id = $1`, [id]); | |
return resultados.rows[0]; | |
}, | |
async actualizar(id, nombre, precio) { | |
const resultados = conexion.query(`update productos | |
set nombre = $1, | |
precio = $2 | |
where id = $3`, [nombre, precio, id]); | |
return resultados; | |
}, | |
async eliminar(id) { | |
const resultados = conexion.query(`delete from productos | |
where id = $1`, [id]); | |
return resultados; | |
}, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment