How do I resolve the warning of serializing a BigInt in SQL queries?
I am continuing to get warnings when making API calls that read:
TypeError: Do not know how to serialize a BigInt at JSON.stringify()
It's not stopping me from querying my database, but I would rather not have warnings thrown at me with every API call.
I'm using uuidv4 (npm package here) which returns a random string of 36 characters (including hyphens). My API call looks like this:
router.post('/:plantName/:quantity/:description/:addedBy', (req, res, next) => {
console.log('API request to add a new plant');
const newPlant = {
name: req.params.plantName,
quantity: req.params.quantity,
description: req.params.description,
addedBy: req.params.addedBy
}
db.addNewPlant(newPlant, (error, results) => {
if(error) {
res.status(500).send('Server Error');
return;
}
res.send(results);
})
})
and exported from database.js as db...
// Add a new plant
const addNewPlant = async (plant, callback) => {
const newID = uuidv4();
const query = `INSERT INTO plants VALUES ("${newID}", "${plant.name}",
${plant.quantity}, "${plant.description}", "${plant.addedBy}")`;
try {
const connection = await pool.getConnection();
const response = await connection.query(query);
callback(false, response);
} catch (error) {
console.error(error);
callback(true);
return;
}
}