@@ -38,7 +38,7 @@ use sqlx_core::IndexMap;
38
38
/// ```rust,no_run
39
39
/// # use sqlx_core::connection::ConnectOptions;
40
40
/// # use sqlx_core::error::Error;
41
- /// use sqlx::sqlite ::{SqliteConnectOptions, SqliteJournalMode};
41
+ /// # use sqlx_sqlite ::{SqliteConnectOptions, SqliteJournalMode};
42
42
/// use std::str::FromStr;
43
43
///
44
44
/// # fn main() {
@@ -79,6 +79,9 @@ pub struct SqliteConnectOptions {
79
79
80
80
pub ( crate ) serialized : bool ,
81
81
pub ( crate ) thread_name : Arc < DebugFn < dyn Fn ( u64 ) -> String + Send + Sync + ' static > > ,
82
+
83
+ #[ cfg( feature = "regexp" ) ]
84
+ pub ( crate ) register_regexp_function : bool ,
82
85
}
83
86
84
87
impl Default for SqliteConnectOptions {
@@ -185,6 +188,8 @@ impl SqliteConnectOptions {
185
188
thread_name : Arc :: new ( DebugFn ( |id| format ! ( "sqlx-sqlite-worker-{}" , id) ) ) ,
186
189
command_channel_size : 50 ,
187
190
row_channel_size : 50 ,
191
+ #[ cfg( feature = "regexp" ) ]
192
+ register_regexp_function : false ,
188
193
}
189
194
}
190
195
@@ -431,8 +436,8 @@ impl SqliteConnectOptions {
431
436
/// will be loaded in the order they are added.
432
437
/// ```rust,no_run
433
438
/// # use sqlx_core::error::Error;
434
- /// use std::str::FromStr;
435
- /// use sqlx::sqlite ::SqliteConnectOptions;
439
+ /// # use std::str::FromStr;
440
+ /// # use sqlx_sqlite ::SqliteConnectOptions;
436
441
/// # fn options() -> Result<SqliteConnectOptions, Error> {
437
442
/// let options = SqliteConnectOptions::from_str("sqlite://data.db")?
438
443
/// .extension("vsv")
@@ -458,4 +463,29 @@ impl SqliteConnectOptions {
458
463
. insert ( extension_name. into ( ) , Some ( entry_point. into ( ) ) ) ;
459
464
self
460
465
}
466
+
467
+ /// Register a regexp function that allows using regular expressions in queries.
468
+ ///
469
+ /// ```
470
+ /// # use std::str::FromStr;
471
+ /// # use sqlx::{ConnectOptions, Connection, Row};
472
+ /// # use sqlx_sqlite::SqliteConnectOptions;
473
+ /// # async fn run() -> sqlx::Result<()> {
474
+ /// let mut sqlite = SqliteConnectOptions::from_str("sqlite://:memory:")?
475
+ /// .with_regexp()
476
+ /// .connect()
477
+ /// .await?;
478
+ /// let tables = sqlx::query("SELECT name FROM sqlite_schema WHERE name REGEXP 'foo(\\d+)bar'")
479
+ /// .fetch_all(&mut sqlite)
480
+ /// .await?;
481
+ /// # Ok(())
482
+ /// # }
483
+ /// ```
484
+ ///
485
+ /// This uses the [`regex`] crate, and is only enabled when you enable the `regex` feature is enabled on sqlx
486
+ #[ cfg( feature = "regexp" ) ]
487
+ pub fn with_regexp ( mut self ) -> Self {
488
+ self . register_regexp_function = true ;
489
+ self
490
+ }
461
491
}
0 commit comments