I'm using JavaScript and PostgreSQL and I'm wondering if the code and syntax is right written because I'm getting strange errors in different situations.
Example:
function putDbEvents({ description, creatorId, attendeeId }) {
return pool
.query(`INSERT INTO events (${description}, ${creatorId}), ${attendeeId}`)
.then(() => pool.end())
.catch(console.log);
}
My questions:
- should it be {} at the first row of function? I think only ()?
- should it be like that insert into or maybe like this
INSERT INTO events ('description', creatorId, attendeeId) VALUES then (${}...
This is the create table code:
const createEventsRes = await pool.query(
"CREATE TABLE IF NOT EXISTS events (id serial PRIMARY KEY, description TEXT, creatorId INTEGER, attendeeId INTEGER)"
);
I wanna create a table so every time you add something it should add an id to it automatically and you just pass description, id, id, to it and the fourth is optional so not needed in this case, and want to see if the syntax is right.