pub struct OrmItemReaderBuilder<'a, I>where
I: EntityTrait,{ /* private fields */ }orm only.Expand description
Builder for creating a OrmItemReader.
This builder provides a convenient way to configure and create a OrmItemReader
with custom parameters like page size and database connection.
It follows the builder pattern to ensure all required components are provided
before creating the reader instance.
§Builder Pattern Benefits
- Fluent API: Method chaining for readable configuration
- Compile-time Safety: Required fields are enforced at build time
- Flexibility: Optional parameters can be omitted
- Validation: Build method validates all required components are present
§Required Components
The following components must be set before calling build():
- Connection: Database connection for executing queries
- Query: SeaORM select query to execute
§Optional Components
- Page Size: When set, enables pagination for memory-efficient reading
§Usage Pattern
let reader = OrmItemReaderBuilder::new()
.connection(&db) // Required
.query(entity_query) // Required
.page_size(100) // Optional
.build(); // Creates the reader§Examples
use spring_batch_rs::item::orm::OrmItemReaderBuilder;
use sea_orm::{Database, EntityTrait, FromQueryResult};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, FromQueryResult, Deserialize, Serialize)]
struct Order {
id: i32,
customer_name: String,
total_amount: f64,
status: String,
}
// Create database connection
let db = Database::connect("postgresql://user:pass@localhost/db").await?;
// Create a query (assuming you have an orders entity)
// let query = orders::Entity::find()
// .filter(orders::Column::Status.eq("pending"));
// Create the reader with explicit type annotations
// let reader: OrmItemReader<orders::Entity> = OrmItemReaderBuilder::new()
// .connection(&db)
// .query(query)
// .page_size(100) // Process 100 orders at a time
// .build();Implementations§
Source§impl<'a, I> OrmItemReaderBuilder<'a, I>
impl<'a, I> OrmItemReaderBuilder<'a, I>
Sourcepub fn page_size(self, page_size: u64) -> Self
pub fn page_size(self, page_size: u64) -> Self
Sets the page size for the reader.
When set, the reader will use pagination to load data in chunks of the specified size. This is useful for processing large datasets without loading everything into memory.
§Memory Management
- Small page sizes (e.g., 10-100): Lower memory usage, more database round trips
- Large page sizes (e.g., 1000-10000): Higher memory usage, fewer database round trips
- No pagination (None): All data loaded at once, highest memory usage
§Performance Considerations
- Choose page size based on available memory and network latency
- Consider the size of your data rows when setting page size
- Monitor memory usage and adjust as needed
§Arguments
page_size- The number of items to read per page (must be > 0 for meaningful pagination)
§Returns
The updated OrmItemReaderBuilder instance for method chaining.
§Examples
use spring_batch_rs::item::orm::OrmItemReaderBuilder;
use sea_orm::FromQueryResult;
use serde::{Deserialize, Serialize};
// In practice, you would use actual SeaORM entities
// #[derive(Debug, Clone, FromQueryResult)]
// struct Record {
// id: i32,
// data: String,
// }
//
// let builder = OrmItemReaderBuilder::<record::Entity>::new()
// .page_size(50); // Process 50 records at a timeSourcepub fn query(self, query: Select<I>) -> Self
pub fn query(self, query: Select<I>) -> Self
Sets the SeaORM select query for the reader.
This query will be executed to fetch data from the database. The query can include filters, joins, ordering, and other SeaORM query operations. The query will be cloned for each page fetch, so it should be relatively lightweight to clone.
§Query Design Considerations
- Ordering: Include
ORDER BYclauses for consistent pagination - Filtering: Apply filters to reduce the dataset size
- Joins: Use joins to fetch related data in a single query
- Indexing: Ensure proper database indexes for query performance
§Pagination Compatibility
When using pagination, the query should:
- Have a deterministic order (use ORDER BY)
- Not use LIMIT/OFFSET (handled by the paginator)
- Be compatible with SeaORM’s paginator
§Arguments
query- The SeaORM select query to execute
§Returns
The updated OrmItemReaderBuilder instance for method chaining.
§Examples
use spring_batch_rs::item::orm::OrmItemReaderBuilder;
use sea_orm::{EntityTrait, QueryFilter};
use serde::{Deserialize, Serialize};
// In practice, you would use actual SeaORM entities
// let query = user::Entity::find()
// .filter(user::Column::Active.eq(true))
// .order_by_asc(user::Column::Id);
//
// let builder = OrmItemReaderBuilder::<user::Entity>::new()
// .query(query);Sourcepub fn connection(self, connection: &'a DatabaseConnection) -> Self
pub fn connection(self, connection: &'a DatabaseConnection) -> Self
Sets the database connection for the reader.
This connection will be used to execute the SeaORM queries. The connection must remain valid for the entire lifetime of the reader, which is enforced by the lifetime parameter ’a.
§Connection Management
- The connection is borrowed, not owned by the reader
- Ensure the connection pool/manager outlives the reader
- The connection should be properly configured for your database
§Database Compatibility
SeaORM supports multiple databases:
- PostgreSQL
- MySQL
- SQLite
- SQL Server (via sqlx)
§Arguments
connection- The SeaORM database connection (must outlive the reader)
§Returns
The updated OrmItemReaderBuilder instance for method chaining.
§Examples
use spring_batch_rs::item::orm::OrmItemReaderBuilder;
use sea_orm::{Database, EntityTrait};
use serde::{Deserialize, Serialize};
let db = Database::connect("sqlite::memory:").await?;
// In practice, you would use actual SeaORM entities
// let builder = OrmItemReaderBuilder::<product::Entity>::new()
// .connection(&db);Sourcepub fn build(self) -> OrmItemReader<'a, I>
pub fn build(self) -> OrmItemReader<'a, I>
Builds the ORM item reader with the configured parameters.
This method validates that all required parameters have been set and creates
a new OrmItemReader instance.
§Returns
A configured OrmItemReader instance
§Panics
Panics if required parameters (connection and query) are missing.
§Validation
The builder performs the following validation:
- Ensures a database connection has been provided
- Ensures a SeaORM query has been provided
- Page size is optional and defaults to loading all data at once
If any required parameter is missing, the method will panic with a descriptive error message.
§Examples
use spring_batch_rs::item::orm::OrmItemReaderBuilder;
use sea_orm::{Database, EntityTrait};
let db = Database::connect("sqlite::memory:").await?;
// With pagination
// let reader = OrmItemReaderBuilder::new()
// .connection(&db)
// .query(MyEntity::find())
// .page_size(100)
// .build();
// Without pagination (load all at once)
// let reader = OrmItemReaderBuilder::new()
// .connection(&db)
// .query(MyEntity::find())
// .build();Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new OrmItemReaderBuilder.
This is the entry point for the builder pattern. It creates a new builder instance with all fields set to their default values (None for optional fields).
§Builder Lifecycle
- Creation:
new()creates an empty builder - Configuration: Use setter methods to configure the reader
- Validation:
build()validates and creates the final reader
§Examples
use spring_batch_rs::item::orm::OrmItemReaderBuilder;
use sea_orm::EntityTrait;
use serde::{Deserialize, Serialize};
// In practice, you would use actual SeaORM entities
// let builder = OrmItemReaderBuilder::<record::Entity>::new()
// .page_size(50); // Process 50 records at a timeTrait Implementations§
Source§impl<I> Default for OrmItemReaderBuilder<'_, I>where
I: EntityTrait,
impl<I> Default for OrmItemReaderBuilder<'_, I>where
I: EntityTrait,
Auto Trait Implementations§
impl<'a, I> Freeze for OrmItemReaderBuilder<'a, I>
impl<'a, I> !RefUnwindSafe for OrmItemReaderBuilder<'a, I>
impl<'a, I> Send for OrmItemReaderBuilder<'a, I>
impl<'a, I> Sync for OrmItemReaderBuilder<'a, I>
impl<'a, I> Unpin for OrmItemReaderBuilder<'a, I>where
I: Unpin,
impl<'a, I> UnsafeUnpin for OrmItemReaderBuilder<'a, I>
impl<'a, I> !UnwindSafe for OrmItemReaderBuilder<'a, 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
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
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.