Answer the question
In order to leave comments, you need to log in
How to write this code correctly?
good afternoon comrades
Recently I started to study programming and backend, I connect to the database
Before that I used the pg library, but now I started connecting to a remote server, using knex
I don’t understand how to write this part of the code ((
app.put("/todos/:id", async(req, res) => {
try {
const {id} = req.params;
const {description} = req.body;
const updateTodo = await knex(
"UPDATE todo SET description = $1 WHERE todo_id = $2",
[description, id]
);
res.json("Todo was updated!")
} catch (err) {
console.log(err.message)
}
});
Answer the question
In order to leave comments, you need to log in
and what are you unable to do? connect? if yes, then the connection to knex looks like this:
var knex = require('knex')({
client: 'mysql',
connection: {
host : '127.0.0.1',
user : 'your_database_user',
password : 'your_database_password',
database : 'myapp_test'
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question