Use params instead of format for fetching comments

main
Elnu 2 years ago
parent 89e609c54a
commit d94cf625f8

@ -32,12 +32,12 @@ impl Database {
pub fn get_comments(&self, content_id: &str) -> Result<Vec<Comment>> { pub fn get_comments(&self, content_id: &str) -> Result<Vec<Comment>> {
self.conn self.conn
.prepare(&format!("SELECT id, author, email, text, timestamp FROM comment WHERE content_id='{content_id}' AND parent IS NULL ORDER BY timestamp DESC"))? .prepare("SELECT id, author, email, text, timestamp FROM comment WHERE content_id=?1 AND parent IS NULL ORDER BY timestamp DESC")?
.query_map([], |row| { .query_map(params![content_id], |row| {
let id = row.get::<usize, Option<i64>>(0)?.unwrap(); let id = row.get::<usize, Option<i64>>(0)?.unwrap();
let replies = self.conn let replies = self.conn
.prepare(&format!("SELECT id, author, email, text, timestamp FROM comment WHERE parent={id}"))? .prepare("SELECT id, author, email, text, timestamp FROM comment WHERE parent=?1")?
.query_map([], |row| { .query_map(params![id], |row| {
Ok(Comment { Ok(Comment {
id: row.get(0)?, id: row.get(0)?,
author: row.get(1)?, author: row.get(1)?,

Loading…
Cancel
Save