-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
kirkbyers
committed
Mar 31, 2024
1 parent
5cd7192
commit 5fa410f
Showing
3 changed files
with
38 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod jobs; | ||
pub mod sm_scrape; | ||
pub mod subscriptions; | ||
mod utils; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
pub fn create_paginator(table_name: &str) -> impl Fn(&str, &str, &str, &str, u32, u32) -> String { | ||
let table_name = table_name.to_string(); // Clone table_name | ||
let paginate = move |columns: &str, q: &str, sort_by: &str, sort_direction: &str, limit: u32, offset: u32| { | ||
let mut result = String::from("SELECT "); | ||
result.push_str(columns); | ||
|
||
result.push_str(format!(" FROM {}", table_name).as_str()); | ||
|
||
if !q.is_empty() { | ||
result.push_str(format!(" WHERE {}", q).as_str()); | ||
} | ||
|
||
if !sort_by.is_empty() { | ||
result.push_str(format!(" ORDER BY {}", sort_by).as_str()); | ||
if !sort_direction.is_empty() { | ||
result.push_str(format!(" {}", sort_direction).as_str()); | ||
} else { | ||
result.push_str(" ASC"); | ||
} | ||
} | ||
|
||
if limit > 0 { | ||
result.push_str(format!(" LIMIT {}", limit).as_str()); | ||
} | ||
|
||
if offset > 0 { | ||
result.push_str(format!(" OFFSET {}", offset.to_string().as_str()).as_str()); | ||
} | ||
|
||
result.push(';'); | ||
result | ||
}; | ||
paginate | ||
} |