Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ mac_address = ["sqlx-core/mac_address", "sqlx-macros?/mac_address", "sqlx-postgr
rust_decimal = ["sqlx-core/rust_decimal", "sqlx-macros?/rust_decimal", "sqlx-mysql?/rust_decimal", "sqlx-postgres?/rust_decimal"]
time = ["sqlx-core/time", "sqlx-macros?/time", "sqlx-mysql?/time", "sqlx-postgres?/time", "sqlx-sqlite?/time"]
uuid = ["sqlx-core/uuid", "sqlx-macros?/uuid", "sqlx-mysql?/uuid", "sqlx-postgres?/uuid", "sqlx-sqlite?/uuid"]
regexp = ["sqlx-sqlite?/regexp"]
regexp = ["sqlx-sqlite?/regexp", "sqlx-macros?/regexp"]
bstr = ["sqlx-core/bstr"]

[workspace.dependencies]
Expand Down
2 changes: 2 additions & 0 deletions sqlx-macros-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ rust_decimal = ["sqlx-core/rust_decimal", "sqlx-mysql?/rust_decimal", "sqlx-post
time = ["sqlx-core/time", "sqlx-mysql?/time", "sqlx-postgres?/time", "sqlx-sqlite?/time"]
uuid = ["sqlx-core/uuid", "sqlx-mysql?/uuid", "sqlx-postgres?/uuid", "sqlx-sqlite?/uuid"]

regexp = ["sqlx-sqlite?/regexp"]

[dependencies]
sqlx-core = { workspace = true, features = ["offline"] }
sqlx-mysql = { workspace = true, features = ["offline", "migrate"], optional = true, default-features = false }
Expand Down
2 changes: 2 additions & 0 deletions sqlx-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ time = ["sqlx-macros-core/time"]
uuid = ["sqlx-macros-core/uuid"]
json = ["sqlx-macros-core/json"]

regexp = ["sqlx-macros-core/regexp"]

[dependencies]
sqlx-core = { workspace = true, features = ["any"] }
sqlx-macros-core = { workspace = true }
Expand Down
7 changes: 6 additions & 1 deletion sqlx-sqlite/src/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ impl SqliteConnectOptions {
// Soft limit on the number of rows that `ANALYZE` touches per index.
pragmas.insert("analysis_limit".into(), None);

#[cfg(feature = "regexp")]
let register_regexp_function = std::env::var("SQLX_SQLITE_REGISTER_REGEXP")
.ok()
.is_some_and(|val| val.eq_ignore_ascii_case("true") || val == "1");

Self {
filename: Cow::Borrowed(Path::new(":memory:")),
in_memory: false,
Expand All @@ -214,7 +219,7 @@ impl SqliteConnectOptions {
row_channel_size: 50,
optimize_on_close: OptimizeOnClose::Disabled,
#[cfg(feature = "regexp")]
register_regexp_function: false,
register_regexp_function,
}
}

Expand Down
16 changes: 16 additions & 0 deletions tests/sqlite/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,4 +358,20 @@ async fn test_column_override_exact_nullable() -> anyhow::Result<()> {
Ok(())
}

/// Requires SQLX_SQLITE_REGISTER_REGEXP environment variable to compile and succeed.
#[cfg(feature = "regexp")]
#[sqlx_macros::test]
async fn test_regexp_function_is_registered_via_env() -> anyhow::Result<()> {
let mut conn = new::<Sqlite>().await?;

let record =
sqlx::query!(r#"select id as "id?: MyInt" from tweet where text regexp 'is pretty cool'"#)
.fetch_one(&mut conn)
.await?;

assert_eq!(record.id, Some(MyInt(1)));

Ok(())
}

// we don't emit bind parameter typechecks for SQLite so testing the overrides is redundant
Loading