@@ -3,7 +3,6 @@ use core::{assert_matches::debug_assert_matches, fmt::Display};
33use alloc:: { string:: ToString , vec:: Vec } ;
44use serde:: Serialize ;
55use sqlite_nostd:: { self as sqlite, Connection , ManagedStmt , ResultCode } ;
6- use streaming_iterator:: StreamingIterator ;
76
87use crate :: {
98 error:: SQLiteError ,
@@ -25,7 +24,7 @@ use super::{
2524/// used frequently as an optimization, but we're not taking advantage of that yet.
2625pub struct StorageAdapter {
2726 pub db : * mut sqlite:: sqlite3 ,
28- progress_stmt : ManagedStmt ,
27+ pub progress_stmt : ManagedStmt ,
2928 time_stmt : ManagedStmt ,
3029}
3130
@@ -78,37 +77,22 @@ impl StorageAdapter {
7877 Ok ( ( ) )
7978 }
8079
81- pub fn local_progress (
82- & self ,
83- ) -> Result <
84- impl StreamingIterator < Item = Result < PersistedBucketProgress , ResultCode > > ,
85- ResultCode ,
86- > {
87- self . progress_stmt . reset ( ) ?;
88-
89- fn step ( stmt : & ManagedStmt ) -> Result < Option < PersistedBucketProgress > , ResultCode > {
90- if stmt. step ( ) ? == ResultCode :: ROW {
91- let bucket = stmt. column_text ( 0 ) ?;
92- let count_at_last = stmt. column_int64 ( 1 ) ;
93- let count_since_last = stmt. column_int64 ( 2 ) ;
94-
95- return Ok ( Some ( PersistedBucketProgress {
96- bucket,
97- count_at_last,
98- count_since_last,
99- } ) ) ;
100- }
101-
80+ pub fn step_progress ( & self ) -> Result < Option < PersistedBucketProgress > , ResultCode > {
81+ if self . progress_stmt . step ( ) ? == ResultCode :: ROW {
82+ let bucket = self . progress_stmt . column_text ( 0 ) ?;
83+ let count_at_last = self . progress_stmt . column_int64 ( 1 ) ;
84+ let count_since_last = self . progress_stmt . column_int64 ( 2 ) ;
85+
86+ Ok ( Some ( PersistedBucketProgress {
87+ bucket,
88+ count_at_last,
89+ count_since_last,
90+ } ) )
91+ } else {
92+ // Done
93+ self . progress_stmt . reset ( ) ?;
10294 Ok ( None )
10395 }
104-
105- Ok ( streaming_iterator:: from_fn ( || {
106- match step ( & self . progress_stmt ) {
107- Err ( e) => Some ( Err ( e) ) ,
108- Ok ( Some ( other) ) => Some ( Ok ( other) ) ,
109- Ok ( None ) => None ,
110- }
111- } ) )
11296 }
11397
11498 pub fn reset_progress ( & self ) -> Result < ( ) , ResultCode > {
@@ -239,10 +223,11 @@ impl StorageAdapter {
239223 }
240224
241225 pub fn now ( & self ) -> Result < Timestamp , ResultCode > {
242- self . time_stmt . reset ( ) ?;
243226 self . time_stmt . step ( ) ?;
227+ let res = Timestamp ( self . time_stmt . column_int64 ( 0 ) ) ;
228+ self . time_stmt . reset ( ) ?;
244229
245- Ok ( Timestamp ( self . time_stmt . column_int64 ( 0 ) ) )
230+ Ok ( res )
246231 }
247232}
248233
0 commit comments