aboutsummaryrefslogtreecommitdiff
path: root/src/db.rs
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-02-20 22:57:33 +0000
committerFuwn <[email protected]>2021-02-20 22:57:33 +0000
commit0a8126ac5330fc022b6d1b5fb4b9c2fa38028ef7 (patch)
treec4f1201aeea4fbac52fa033cda8c3f72beb062fa /src/db.rs
parentchore: update log (diff)
downloadchan-0a8126ac5330fc022b6d1b5fb4b9c2fa38028ef7.tar.xz
chan-0a8126ac5330fc022b6d1b5fb4b9c2fa38028ef7.zip
chore: formatting
Diffstat (limited to 'src/db.rs')
-rw-r--r--src/db.rs98
1 files changed, 49 insertions, 49 deletions
diff --git a/src/db.rs b/src/db.rs
index 4eea4c7..a88b2bf 100644
--- a/src/db.rs
+++ b/src/db.rs
@@ -4,71 +4,71 @@ use crate::structures::*;
/// Create a new thread in the SQLite database.
pub fn new_thread(mut thread: Thread) -> Result<()> {
- // Open SQLite database file.
- let db = Connection::open("chan.db")?;
+ // Open SQLite database file.
+ let db = Connection::open("chan.db")?;
- // If the name field in the POST request is empty, user should be "anonymous".
- if thread.name == "" {
- thread.name = "Anonymous".to_owned();
- }
+ // If the name field in the POST request is empty, user should be "anonymous".
+ if thread.name == "" {
+ thread.name = "Anonymous".to_owned();
+ }
- // Add thread entry to database.
- db.execute(
- "INSERT INTO threads (board, name, comment) VALUES (?1, ?2, ?3)",
- params![thread.board, thread.name, thread.comment]
- )?;
+ // Add thread entry to database.
+ db.execute(
+ "INSERT INTO threads (board, name, comment) VALUES (?1, ?2, ?3)",
+ params![thread.board, thread.name, thread.comment]
+ )?;
- Ok(())
+ Ok(())
}
/// Get all threads from the SQLite databse.
pub fn _get_all_threads() -> Result<Vec<Thread>, SQLError> {
- // Open SQLite database file.
- let db = Connection::open("chan.db")?;
+ // Open SQLite database file.
+ let db = Connection::open("chan.db")?;
- // Get all entries from the thread table.
- let mut statement = db.prepare("SELECT board, name, comment FROM threads")?;
- let threads = statement.query_map(params![], |row| {
- Ok(Thread {
- board: row.get(0)?,
- name: row.get(1)?,
- comment: row.get(2)?
- })
- })?;
- threads.collect()
+ // Get all entries from the thread table.
+ let mut statement = db.prepare("SELECT board, name, comment FROM threads")?;
+ let threads = statement.query_map(params![], |row| {
+ Ok(Thread {
+ board: row.get(0)?,
+ name: row.get(1)?,
+ comment: row.get(2)?
+ })
+ })?;
+ threads.collect()
}
/// Get all boards from the SQLite databse.
pub fn get_boards() -> Result<Vec<Board>, SQLError> {
- // Open SQLite database file.
- let db = Connection::open("chan.db")?;
+ // Open SQLite database file.
+ let db = Connection::open("chan.db")?;
- // Get all entries from the thread table.
- let mut statement = db.prepare("SELECT tag, name, nsfw, disabled FROM boards")?;
- let boards = statement.query_map(params![], |row| {
- Ok(Board {
- tag: row.get(0)?,
- name: row.get(1)?,
- nsfw: row.get(2)?,
- disabled: row.get(3)?
- })
- })?;
- boards.collect()
+ // Get all entries from the thread table.
+ let mut statement = db.prepare("SELECT tag, name, nsfw, disabled FROM boards")?;
+ let boards = statement.query_map(params![], |row| {
+ Ok(Board {
+ tag: row.get(0)?,
+ name: row.get(1)?,
+ nsfw: row.get(2)?,
+ disabled: row.get(3)?
+ })
+ })?;
+ boards.collect()
}
/// Get all threads from a specific board within the SQLite databse.
pub fn get_threads(board: String) -> Result<Vec<Thread>, SQLError> {
- // Open SQLite database file.
- let db = Connection::open("chan.db")?;
+ // Open SQLite database file.
+ let db = Connection::open("chan.db")?;
- // Get all entries from the thread table.
- let mut statement = db.prepare("SELECT board, name, comment FROM threads WHERE board = (?)")?;
- let threads = statement.query_map(params![board], |row| {
- Ok(Thread {
- board: row.get(0)?,
- name: row.get(1)?,
- comment: row.get(2)?
- })
- })?;
- threads.collect()
+ // Get all entries from the thread table.
+ let mut statement = db.prepare("SELECT board, name, comment FROM threads WHERE board = (?)")?;
+ let threads = statement.query_map(params![board], |row| {
+ Ok(Thread {
+ board: row.get(0)?,
+ name: row.get(1)?,
+ comment: row.get(2)?
+ })
+ })?;
+ threads.collect()
}