Skip to content

Commit 5798505

Browse files
committed
show solved count for searched link
1 parent a904ea9 commit 5798505

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
[package]
22
name = "abhyas"
3-
version = "1.2.0"
3+
version = "1.4.0"
44
edition = "2021"
55
authors = ["Harshal Jadhav <bestt1315@gmail.com>"]
66
homepage = "https://github.com/halshar/abhyas"
77
description = "Abhyas is a Rust command-line application for managing and interacting with a database of links."
88
readme = "README.md"
9-
repository = "https://github.com/halshar/abhyas"
9+
repository = "https://github.com/halshar/abhyas"
1010
license = "GPL-3.0-or-later"
1111

1212
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

src/cli.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,14 @@ fn search_link_options(db: &Db) -> Result<(), CustomErrors> {
273273
}
274274
};
275275

276+
match db.get_searched_link_count(&link) {
277+
Ok(val) => match val {
278+
Some(solved_count) => pretty_print(&[(link.clone(), solved_count)]),
279+
None => pretty_print(&[(link.clone(), 0)]),
280+
},
281+
Err(e) => return Err(e),
282+
};
283+
276284
single_link_options(db, &link)?;
277285

278286
Ok(())

src/database.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,27 @@ impl Db {
136136
}
137137
}
138138

139+
pub fn get_searched_link_count(&self, link: &str) -> Result<Option<i32>, CustomErrors> {
140+
let mut stmt = match self.conn.prepare(
141+
"SELECT solved_count FROM links
142+
WHERE link = ?1;",
143+
) {
144+
Ok(val) => val,
145+
Err(_) => return Err(CustomErrors::StatementFailed),
146+
};
147+
148+
match stmt.query_row([&link], |row| {
149+
let solved_count: i32 = row.get(0)?;
150+
Ok(solved_count)
151+
}) {
152+
Ok(solved_count) => Ok(Some(solved_count)),
153+
Err(rusqlite::Error::QueryReturnedNoRows) => Ok(None),
154+
Err(_) => Err(CustomErrors::Others(
155+
"Error: Something went wrong while fetching link count".to_owned(),
156+
)),
157+
}
158+
}
159+
139160
pub fn mark_as_complete(&self, link: &str) -> Result<(), CustomErrors> {
140161
match self.conn.execute(
141162
"UPDATE links

0 commit comments

Comments
 (0)