Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created June 28, 2019 22:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/3760ff536d29bffb3c3a92fdd650d45d to your computer and use it in GitHub Desktop.
Save parzibyte/3760ff536d29bffb3c3a92fdd650d45d to your computer and use it in GitHub Desktop.
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