-
Notifications
You must be signed in to change notification settings - Fork 189
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expand docs on Raw SQL Queries #1124
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks :) Good addition!
Co-authored-by: Marc Scholten <marcphilipscholten@gmail.com>
-- Get all Projects | ||
let table :: Text = "projects" | ||
-- Use PG.Identifier to prevent SQL injection | ||
result :: [Project] <- sqlQuery "SELECT * FROM ?" [PG.Identifier table] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you wanted to do SELECT * FROM ? WHERE id = ?
how do you pass the params?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then I'd do it like this:
let id :: Id Project = ".."
result :: [Project] <- sqlQuery "SELECT * FROM ? WHERE id = ?" (PG.Identifier table, id)
do | ||
-- Get all Projects | ||
let table :: Text = "projects" | ||
-- Use PG.Identifier to prevent SQL injection |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a note about SQL injection
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks 馃憤 good job
Took me a while to figure how to do it, so might help others/ future me 馃樃