aboutsummaryrefslogtreecommitdiff
path: root/src/db
diff options
context:
space:
mode:
Diffstat (limited to 'src/db')
-rw-r--r--src/db/db.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/db/db.rs b/src/db/db.rs
index 4c2d9a2..590f3ea 100644
--- a/src/db/db.rs
+++ b/src/db/db.rs
@@ -108,6 +108,15 @@ pub fn next_ready(conn: &Connection) -> Option<Card> {
})
}
+pub fn count_available(conn: &Connection) -> Option<i32> {
+ let now = time::now().ok()?;
+ let mut stmt = conn.prepare("SELECT COUNT(*) FROM cards WHERE ready <= ? AND deleted IS NULL").ok()?;
+
+ let mut rows = stmt.query([now]).ok()?;
+ let row = rows.next().ok()??;
+ row.get(0).ok()?
+}
+
pub fn update(conn: &Connection, question: &String, state: &space_repetition::State) -> Result<()> {
let now = time::now()?;
let ready = now + state.get_interval_seconds();