@@ -70,6 +70,7 @@ pub struct SqliteConnectOptions {
7070 pub ( crate ) log_settings : LogSettings ,
7171 pub ( crate ) immutable : bool ,
7272 pub ( crate ) vfs : Option < Cow < ' static , str > > ,
73+ pub ( crate ) thread_stack_size : Option < usize > ,
7374
7475 pub ( crate ) pragmas : IndexMap < Cow < ' static , str > , Option < Cow < ' static , str > > > ,
7576
@@ -204,6 +205,7 @@ impl SqliteConnectOptions {
204205 log_settings : Default :: default ( ) ,
205206 immutable : false ,
206207 vfs : None ,
208+ thread_stack_size : None ,
207209 pragmas,
208210 #[ cfg( feature = "load-extension" ) ]
209211 extensions : Default :: default ( ) ,
@@ -233,6 +235,42 @@ impl SqliteConnectOptions {
233235 & self . filename
234236 }
235237
238+ /// Set the thread stack size in bytes for the SQLite worker thread.
239+ ///
240+ /// **This is an advanced option.** By default (`None`), SQLx uses the Rust standard library's
241+ /// default stack size (typically 2 MB), which is safe for most use cases including user-supplied
242+ /// callbacks and platform-specific requirements.
243+ ///
244+ /// Only set this if you have a specific reason to do so, such as running in an embedded environment
245+ /// with constrained memory. Be aware that:
246+ /// - User-supplied callbacks (hooks, custom functions) run on this thread and may have unpredictable
247+ /// stack requirements
248+ /// - Different platforms (32-bit vs 64-bit) have different stack size requirements
249+ /// - Setting this too low may cause stack overflow crashes
250+ ///
251+ /// # Example
252+ ///
253+ /// ```rust,no_run
254+ /// # use sqlx_sqlite::SqliteConnectOptions;
255+ /// # use std::str::FromStr;
256+ /// # fn example() -> Result<(), Box<dyn std::error::Error>> {
257+ /// let options = SqliteConnectOptions::from_str("sqlite::memory:")?
258+ /// .thread_stack_size(1024 * 1024); // 1 MB - use with caution!
259+ /// # Ok(())
260+ /// # }
261+ /// ```
262+ pub fn thread_stack_size ( mut self , size : usize ) -> Self {
263+ self . thread_stack_size = Some ( size) ;
264+ self
265+ }
266+
267+ /// Get the current thread stack size in bytes.
268+ ///
269+ /// Returns `None` if using the default stack size from the Rust standard library.
270+ pub fn get_thread_stack_size ( & self ) -> Option < usize > {
271+ self . thread_stack_size
272+ }
273+
236274 /// Set the enforcement of [foreign key constraints](https://www.sqlite.org/pragma.html#pragma_foreign_keys).
237275 ///
238276 /// SQLx chooses to enable this by default so that foreign keys function as expected,
0 commit comments