Created
April 29, 2019 08:32
-
-
Save vouill/c7146a0fe515a5f32528a32a4d7aa1a5 to your computer and use it in GitHub Desktop.
Preparing SQL queries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// before | |
db.all(`SELECT * FROM POSTS WHERE ID = ${req.params.id};`, function( | |
err, | |
row | |
) { | |
res.send(row); | |
}); | |
// after | |
const stmt = db.prepare("SELECT * FROM POSTS WHERE ID = ?"); | |
stmt.all(req.params.id, function(err, rows) { | |
res.send(rows); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment