pub struct SelectBuilder<I> { /* private fields */ }rdbc only.Expand description
Fluent builder for SQL SELECT statements used by RDBC item readers.
Call SelectBuilder::from to create a builder for a given table, chain
optional filter/order methods, then call SelectBuilder::build_sql to
obtain the final SQL string.
§Type Parameters
I— The item type that will be read from the database. Used only for the keyset key function; when keyset pagination is not neededIcan be any type (e.g. a unit struct).
§Examples
use spring_batch_rs::item::rdbc::SelectBuilder;
struct Product;
let sql = SelectBuilder::<Product>::from("products")
.columns(&["id", "name", "price"])
.where_gte("price", 10.0_f64)
.where_eq("active", true)
.order_by_desc("price")
.build_sql();
assert!(sql.starts_with("SELECT id, name, price FROM products WHERE"));
assert!(sql.contains("ORDER BY price DESC"));Implementations§
Source§impl<I> SelectBuilder<I>
impl<I> SelectBuilder<I>
Sourcepub fn from(table: impl Into<String>) -> Self
pub fn from(table: impl Into<String>) -> Self
Creates a new SelectBuilder targeting the given table.
§Examples
use spring_batch_rs::item::rdbc::SelectBuilder;
struct Row;
let sql = SelectBuilder::<Row>::from("orders").build_sql();
assert_eq!(sql, "SELECT * FROM orders");Sourcepub fn columns(self, cols: &[&str]) -> Self
pub fn columns(self, cols: &[&str]) -> Self
Specifies the columns to select.
When not called (or called with an empty slice), the query uses SELECT *.
§Examples
use spring_batch_rs::item::rdbc::SelectBuilder;
struct Row;
let sql = SelectBuilder::<Row>::from("users")
.columns(&["id", "email"])
.build_sql();
assert_eq!(sql, "SELECT id, email FROM users");Sourcepub fn where_eq(self, col: &str, val: impl Into<ConditionValue>) -> Self
pub fn where_eq(self, col: &str, val: impl Into<ConditionValue>) -> Self
Adds a col = val condition.
§Examples
use spring_batch_rs::item::rdbc::SelectBuilder;
struct Row;
let sql = SelectBuilder::<Row>::from("users")
.where_eq("status", "ACTIVE")
.build_sql();
assert_eq!(sql, "SELECT * FROM users WHERE status = 'ACTIVE'");Sourcepub fn where_not_eq(self, col: &str, val: impl Into<ConditionValue>) -> Self
pub fn where_not_eq(self, col: &str, val: impl Into<ConditionValue>) -> Self
Adds a col != val condition.
§Examples
use spring_batch_rs::item::rdbc::SelectBuilder;
struct Row;
let sql = SelectBuilder::<Row>::from("users")
.where_not_eq("role", "ADMIN")
.build_sql();
assert_eq!(sql, "SELECT * FROM users WHERE role != 'ADMIN'");Sourcepub fn where_gt(self, col: &str, val: impl Into<ConditionValue>) -> Self
pub fn where_gt(self, col: &str, val: impl Into<ConditionValue>) -> Self
Adds a col > val condition.
§Examples
use spring_batch_rs::item::rdbc::SelectBuilder;
struct Row;
let sql = SelectBuilder::<Row>::from("orders")
.where_gt("amount", 100_i32)
.build_sql();
assert_eq!(sql, "SELECT * FROM orders WHERE amount > 100");Sourcepub fn where_gte(self, col: &str, val: impl Into<ConditionValue>) -> Self
pub fn where_gte(self, col: &str, val: impl Into<ConditionValue>) -> Self
Adds a col >= val condition.
§Examples
use spring_batch_rs::item::rdbc::SelectBuilder;
struct Row;
let sql = SelectBuilder::<Row>::from("orders")
.where_gte("score", 4.5_f64)
.build_sql();
assert!(sql.starts_with("SELECT * FROM orders WHERE score >= "));Sourcepub fn where_lt(self, col: &str, val: impl Into<ConditionValue>) -> Self
pub fn where_lt(self, col: &str, val: impl Into<ConditionValue>) -> Self
Adds a col < val condition.
§Examples
use spring_batch_rs::item::rdbc::SelectBuilder;
struct Row;
let sql = SelectBuilder::<Row>::from("items")
.where_lt("stock", 10_i32)
.build_sql();
assert_eq!(sql, "SELECT * FROM items WHERE stock < 10");Sourcepub fn where_lte(self, col: &str, val: impl Into<ConditionValue>) -> Self
pub fn where_lte(self, col: &str, val: impl Into<ConditionValue>) -> Self
Adds a col <= val condition.
§Examples
use spring_batch_rs::item::rdbc::SelectBuilder;
struct Row;
let sql = SelectBuilder::<Row>::from("items")
.where_lte("rank", 100_i32)
.build_sql();
assert_eq!(sql, "SELECT * FROM items WHERE rank <= 100");Sourcepub fn where_like(self, col: &str, pat: &str) -> Self
pub fn where_like(self, col: &str, pat: &str) -> Self
Adds a col LIKE 'pattern' condition.
Single quotes in pat are escaped automatically.
§Examples
use spring_batch_rs::item::rdbc::SelectBuilder;
struct Row;
let sql = SelectBuilder::<Row>::from("users")
.where_like("email", "%@corp.com")
.build_sql();
assert_eq!(sql, "SELECT * FROM users WHERE email LIKE '%@corp.com'");Sourcepub fn where_is_null(self, col: &str) -> Self
pub fn where_is_null(self, col: &str) -> Self
Adds a col IS NULL condition.
§Examples
use spring_batch_rs::item::rdbc::SelectBuilder;
struct Row;
let sql = SelectBuilder::<Row>::from("users")
.where_is_null("deleted_at")
.build_sql();
assert_eq!(sql, "SELECT * FROM users WHERE deleted_at IS NULL");Sourcepub fn where_is_not_null(self, col: &str) -> Self
pub fn where_is_not_null(self, col: &str) -> Self
Adds a col IS NOT NULL condition.
§Examples
use spring_batch_rs::item::rdbc::SelectBuilder;
struct Row;
let sql = SelectBuilder::<Row>::from("users")
.where_is_not_null("confirmed_at")
.build_sql();
assert_eq!(sql, "SELECT * FROM users WHERE confirmed_at IS NOT NULL");Sourcepub fn order_by_asc(self, col: &str) -> Self
pub fn order_by_asc(self, col: &str) -> Self
Appends an ORDER BY col ASC clause.
§Examples
use spring_batch_rs::item::rdbc::SelectBuilder;
struct Row;
let sql = SelectBuilder::<Row>::from("users")
.order_by_asc("created_at")
.build_sql();
assert_eq!(sql, "SELECT * FROM users ORDER BY created_at ASC");Sourcepub fn order_by_desc(self, col: &str) -> Self
pub fn order_by_desc(self, col: &str) -> Self
Appends an ORDER BY col DESC clause.
§Examples
use spring_batch_rs::item::rdbc::SelectBuilder;
struct Row;
let sql = SelectBuilder::<Row>::from("users")
.order_by_desc("score")
.build_sql();
assert_eq!(sql, "SELECT * FROM users ORDER BY score DESC");Sourcepub fn order_by_keyset(
self,
col: &str,
key_fn: impl Fn(&I) -> String + 'static,
) -> Self
pub fn order_by_keyset( self, col: &str, key_fn: impl Fn(&I) -> String + 'static, ) -> Self
Configures keyset (cursor-based) pagination on col.
Clears any previously configured ORDER BY clauses, sets ORDER BY col ASC,
and stores col and key_fn for use by the reader at runtime.
key_fn extracts the cursor value (as a String) from the last item
returned by a page, so the next page can request WHERE col > last_cursor.
§Examples
use spring_batch_rs::item::rdbc::SelectBuilder;
struct Event { id: i64 }
let sql = SelectBuilder::<Event>::from("events")
.order_by_keyset("id", |e: &Event| e.id.to_string())
.build_sql();
assert_eq!(sql, "SELECT * FROM events ORDER BY id ASC");Sourcepub fn build_sql(&self) -> String
pub fn build_sql(&self) -> String
Builds and returns the SQL SELECT statement.
- If no columns were specified, emits
SELECT *. - Multiple WHERE conditions are joined with
AND. - Multiple ORDER BY clauses are joined with
,.
§Examples
use spring_batch_rs::item::rdbc::SelectBuilder;
struct Row;
let sql = SelectBuilder::<Row>::from("orders")
.columns(&["id", "total"])
.where_eq("status", "OPEN")
.where_gt("total", 0_i32)
.order_by_asc("id")
.build_sql();
assert_eq!(
sql,
"SELECT id, total FROM orders WHERE status = 'OPEN' AND total > 0 ORDER BY id ASC"
);Auto Trait Implementations§
impl<I> !RefUnwindSafe for SelectBuilder<I>
impl<I> !Send for SelectBuilder<I>
impl<I> !Sync for SelectBuilder<I>
impl<I> !UnwindSafe for SelectBuilder<I>
impl<I> Freeze for SelectBuilder<I>
impl<I> Unpin for SelectBuilder<I>
impl<I> UnsafeUnpin for SelectBuilder<I>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.