I'm inserting values into a MySQL database using Nodejs mysql2 library.
Here is an example of a prepared statement:
await conn.execute(
'INSERT INTO Friends (id, user, name, gender) VALUES (UUID(), ?, ?, ?)',
[ user, body.name, body.gender ]
);
How can I achieve the above if sometimes the body.gender value is not set? I want several attributes in the http request to be optional and insert all allowed values that have been sent in the http request into the database.
The above code gives an error if I leave body.gender out of the http request.