From e7dc15d8328ca724cb5040ea70eb2a71642c9bf4 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Fri, 11 Jun 2021 21:26:14 -0400 Subject: [PATCH] offset predicate --- .../list_tts_inference_results.rs | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/common_queries/list_tts_inference_results.rs b/src/common_queries/list_tts_inference_results.rs index 533a92f572..10291017b5 100644 --- a/src/common_queries/list_tts_inference_results.rs +++ b/src/common_queries/list_tts_inference_results.rs @@ -502,6 +502,11 @@ impl QueryBuilder { self } + pub fn offset(mut self, offset: Option) -> Self { + self.offset = offset; + self + } + pub fn build_predicates(&self) -> String { // NB: Reverse cursors require us to invert the sort direction. let mut sort_ascending = self.sort_ascending; @@ -622,4 +627,31 @@ mod tests { ORDER BY tts_results.id ASC \ LIMIT ?"); } -} \ No newline at end of file + + #[test] + fn predicates_offset() { + let query_builder = QueryBuilder::new() + .offset(Some(100)); + + assert_eq!(&query_builder.build_predicates(), + " WHERE tts_results.id < ? \ + AND tts_results.user_deleted_at IS NULL \ + AND tts_results.mod_deleted_at IS NULL \ + ORDER BY tts_results.id DESC \ + LIMIT ?"); + } + + #[test] + fn predicates_offset_and_sort_ascending() { + let query_builder = QueryBuilder::new() + .sort_ascending(true) + .offset(Some(100)); + + assert_eq!(&query_builder.build_predicates(), + " WHERE tts_results.id > ? \ + AND tts_results.user_deleted_at IS NULL \ + AND tts_results.mod_deleted_at IS NULL \ + ORDER BY tts_results.id ASC \ + LIMIT ?"); + } +}