Today I learned more about SQL, especially how to create a date column in my db query and how to create a unique index.
date DATE DEFAULT CURRENT_DATE NOT NULL
CREATE UNIQUE INDEX IF NOT EXISTS duplicate_votes_per_day ON votes(voter, date);
SELECT * FROM votes WHERE date = CURRENT_DATE;
SQL is so sensitive to syntax so it's imperative to check for every semicolon, space comma etc!
To create a random voter ID that increments, which helps us see what each individual user is doing on the site without us having to know who they are:
if (!localStorage.getItem('voterId')) {
localStorage.setItem('voterId', String(Math.random()));
}
const voterId = localStorage.getItem('voterId');
SELECT * FROM votes WHERE date = CURRENT_DATE;
SQL is so sensitive to syntax so it's imperative to check for every semicolon, space comma etc!
To create a random voter ID that increments, which helps us see what each individual user is doing on the site without us having to know who they are: if (!localStorage.getItem('voterId')) { localStorage.setItem('voterId', String(Math.random())); } const voterId = localStorage.getItem('voterId');
To parameterize something you can use $1 and $2