diff options
| author | Fuwn <[email protected]> | 2021-02-20 23:22:00 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2021-02-20 23:22:00 +0000 |
| commit | b1b29f1b6c91879838c8b01c4f5a3c4b7a86ec77 (patch) | |
| tree | bf5e932b2ee8e0899743b4963375156ca13ceff0 | |
| parent | chore, fix: refactor returns, grammar. (diff) | |
| download | chan-b1b29f1b6c91879838c8b01c4f5a3c4b7a86ec77.tar.xz chan-b1b29f1b6c91879838c8b01c4f5a3c4b7a86ec77.zip | |
chore, fix, refactor: desc.
chore:
- update readme
fix:
- grammer
refactor:
- undo previous commit return refactor
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | README.md | 29 | ||||
| -rw-r--r-- | chan.db.example | bin | 0 -> 24576 bytes | |||
| -rw-r--r-- | src/db.rs | 15 | ||||
| -rw-r--r-- | src/structures.rs | 4 |
5 files changed, 35 insertions, 14 deletions
@@ -1,2 +1,3 @@ /target /.idea +chan.db @@ -23,25 +23,42 @@ A simple "chan"-like board written in Rust. ``` ## Inspirational -Originally, this project was supposed to be a public [OpenPGP](https://www.openpgp.org/) key server because I was frustrated with the current selection of key servers, but I randomly had the idea to make a "chan"-like forum and I had this sitting around so I made this! +Originally, this project was supposed to be a public [OpenPGP](https://www.openpgp.org/) key server +because I was frustrated with the current selection of key servers, but I randomly had the idea to +make a "chan"-like forum and I had this sitting around so I made this! ## Limitations -At the moment, the board is missing automatic post pruning and moderation features, but I have plans to finish adding them in the near future. As well, at the moment, there has to be a 'empty' thread entry in the 'threads' table within the database, for now. This is becaus of the way that the thread making feature grabs valid board data. I'll probably fix this sometime soon also. +At the moment, the board is missing automatic post pruning and moderation features, but I have plans + to finish adding them in the near future. As well, at the moment, there has to be a 'empty' thread + entry in the 'threads' table within the database, for now. This is because of the way that the + thread making feature grabs valid board data. I'll probably fix this sometime soon also. -Ignore my messy Handlebars templates, I didn't really have a purpose to make them fancy or whatever because of the simplicity of the project. +Ignore my messy Handlebars templates, I didn't really have a purpose to make them fancy or whatever +because of the simplicity of the project. ## Usage 1. Install [Rust](https://www.rust-lang.org/). 2. Clone the repository. -3. `$ cargo run`. +3. Rename the [`chan.db.example`](./chan.db.example) file to `chan.db`. +4. `$ cargo run`. + +### Usage Notes +[`chan.db.example`](./chan.db.example) is the default format of the database. If you ever want to +"restore" the database to its default state, I recommend you keep a copy of the original state of +this file. + +In the future, I will *most likely* add a `setup_db()` function to validate the database state and +properly setup the database when an invalid format is found. ### Adding boards -To add boards, open the example database in a SQLite viewer add a board entry to the 'boards' table (examples provided in database). +To add boards, open the example database in a SQLite viewer add a board entry to the 'boards' table +(examples provided in database). Pre-built binaries *might* be available in the future if there is enough demand for them. ## Contribution -Feel free to make pull requests or open issues if you think a feature should be added or you find a bug, or just anything --- within reason. +Feel free to make pull requests or open issues if you think a feature should be added or you find a +bug, or just anything -- within reason. ### License [GNU Affero General Public License v3.0](https://github.com/fuwn/chan/blob/main/LICENSE.md) diff --git a/chan.db.example b/chan.db.example Binary files differnew file mode 100644 index 0000000..bd7412e --- /dev/null +++ b/chan.db.example @@ -28,13 +28,14 @@ pub fn _get_all_threads() -> Result<Vec<Thread>, SQLError> { // Get all entries from the thread table. let mut statement = db.prepare("SELECT board, name, comment FROM threads")?; - statement.query_map(params![], |row| { + let threads = statement.query_map(params![], |row| { Ok(Thread { board: row.get(0)?, name: row.get(1)?, comment: row.get(2)? }) - })?.collect() + })?; + threads.collect() } /// Get all boards from the SQLite database. @@ -44,14 +45,15 @@ pub fn get_boards() -> Result<Vec<Board>, SQLError> { // Get all entries from the thread table. let mut statement = db.prepare("SELECT tag, name, nsfw, disabled FROM boards")?; - statement.query_map(params![], |row| { + 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)? }) - })?.collect() + })?; + boards.collect() } /// Get all threads from a specific board within the SQLite database. @@ -61,11 +63,12 @@ pub fn get_threads(board: String) -> Result<Vec<Thread>, SQLError> { // Get all entries from the thread table. let mut statement = db.prepare("SELECT board, name, comment FROM threads WHERE board = (?)")?; - statement.query_map(params![board], |row| { + let threads = statement.query_map(params![board], |row| { Ok(Thread { board: row.get(0)?, name: row.get(1)?, comment: row.get(2)? }) - })?.collect() + })?; + threads.collect() } diff --git a/src/structures.rs b/src/structures.rs index 1114bbc..dceecd2 100644 --- a/src/structures.rs +++ b/src/structures.rs @@ -1,4 +1,4 @@ -/// The format a valid SQLlite thread entry should have. +/// The format a valid SQLite thread entry should have. #[derive(FromForm, Debug, Serialize, Deserialize)] pub struct Thread { pub board: String, @@ -6,7 +6,7 @@ pub struct Thread { pub comment: String } -/// The format a valid SQLlite thread entry should have. +/// The format a valid SQLite thread entry should have. #[derive(FromForm, Debug, Serialize, Deserialize, PartialEq)] pub struct Board { pub tag: String, |