1
I am developing an API in Node.js and Knex.js, but I came across a problem, the array that Knex returns in the promise has a JSON inside and is numerical that needs to be validated. However, the key is strange and cannot access its value, so I cannot make a correct answer.
Code:
async dateValidator(request, response){
const {loja, data} = request.body;
const queryCountData = conection('agendamentos').count("data").where({"data": data, 'loja': loja});
queryCountData.then(resp => {
if(resp[0].count >= 13){
response.status(401).json(resp);
}
if(resp < 13){
response.status(201).json(resp);
}
});
}
The resulting JSON:
[
{
"count(data)": 13
}
]
The key to the object is count(data)
. How do I access this object in Javascript, and it has parentheses (()
) within?
I had totally forgotten the option "as" I’m now picking up the knex, I dealt with sql straight and was altomatic this ja, but with the knex is all new
– Geovane
face thank you really
– Geovane