Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updateSession function should contain both insert and update records #6

Open
prdk0 opened this issue Aug 3, 2023 · 0 comments
Open

Comments

@prdk0
Copy link

prdk0 commented Aug 3, 2023

func updateSession(sid string, uid int) {

for example :
if it's a new session, it should insert or else it should update

queryString := INSERT INTO sessions(session_id, user_id)
SELECT $1::VARCHAR, $2
WHERE
NOT EXISTS (
SELECT session_id FROM sessions where session_id = $1
)`
_, err := database.Exec(queryString, sid, currUserId)
checkErrorAndExit(err, "insert")

_, err = database.Exec("UPDATE sessions SET user_id = $2 where session_id = $1", sid, currUserId)
checkErrorAndExit(err, "update")`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant