From c0709481ab33f5d396402473faa2a5266bd1aec8 Mon Sep 17 00:00:00 2001
From: Kubat <mael.martin31@gmail.com>
Date: Sun, 5 Feb 2023 14:54:20 +0100
Subject: [PATCH] DB: Impl load_all and clear history

---
 src/rust/lektor_db/src/connexion.rs | 11 +++++++++--
 src/rust/lektor_db/src/types.rs     |  4 ++++
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/src/rust/lektor_db/src/connexion.rs b/src/rust/lektor_db/src/connexion.rs
index 120f90b0..6021a8a1 100644
--- a/src/rust/lektor_db/src/connexion.rs
+++ b/src/rust/lektor_db/src/connexion.rs
@@ -186,12 +186,19 @@ impl LktDatabaseConnection {
 
     /// Returns the queue history.
     pub fn history(&mut self) -> LktDatabaseResult<Vec<i64>> {
-        todo!()
+        Ok(with_dsl!(history => history
+            .select(id)
+            .order_by(epoch.desc())
+            .load::<i64>(&mut self.sqlite)?
+        ))
     }
 
     /// Clears the history.
     pub fn clear_history(&mut self) -> LktDatabaseResult<()> {
-        todo!()
+        with_dsl! { history => {
+            diesel::delete(history).execute(&mut self.sqlite)?;
+            Ok(())
+        }}
     }
 
     /// Search the history by URIs. We return the local ids.
diff --git a/src/rust/lektor_db/src/types.rs b/src/rust/lektor_db/src/types.rs
index 76a9ed73..45716cfd 100644
--- a/src/rust/lektor_db/src/types.rs
+++ b/src/rust/lektor_db/src/types.rs
@@ -1,3 +1,7 @@
+//! Types exported by the database crate.
+//! TODO: Use [bumpalo](https://docs.rs/bumpalo/3.12.0/bumpalo/) to reduce
+//!       allocation counts?
+
 use hashbrown::HashMap;
 
 pub struct KaraInfo {
-- 
GitLab