Skip to content
Draft
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
492 changes: 255 additions & 237 deletions Cargo.lock

Large diffs are not rendered by default.

27 changes: 21 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ members = [
"examples/postgres/transaction",
"examples/sqlite/todos",
"examples/sqlite/extension",
"tests/mysql/wasm-components/connect-test",
"tests/mysql/wasm-components/execute-query-test",
"tests/mysql/wasm-components/pool-crud-test",
"tests/mysql/wasm-components/prepared-query-test",
]

[workspace.package]
Expand Down Expand Up @@ -186,10 +190,12 @@ mac_address = "1.1.5"
rust_decimal = { version = "1.26.1", default-features = false, features = ["std"] }
time = { version = "0.3.36", features = ["formatting", "parsing", "macros"] }
uuid = "1.1.2"

tokio-util = { version = "*" }
# Common utility crates
cfg-if = "1.0.0"
dotenvy = { version = "0.15.0", default-features = false }
wasip3 ={ version = "0.2.0" ,default-features = false }
wit-bindgen = { version = "0.46", default-features = false }

# Runtimes
[workspace.dependencies.async-global-executor]
Expand All @@ -206,7 +212,7 @@ default-features = false

[workspace.dependencies.tokio]
version = "1"
features = ["time", "net", "sync", "fs", "io-util", "rt"]
features = ["time", "sync", "io-util", "rt"]
default-features = false

[dependencies]
Expand All @@ -222,8 +228,10 @@ anyhow = "1.0.52"
time_ = { version = "0.3.2", package = "time" }
futures-util = { version = "0.3.19", default-features = false, features = ["alloc"] }
env_logger = "0.11"
async-std = { workspace = true, features = ["attributes"] }
tokio = { version = "1.15.0", features = ["full"] }
futures = "0.3"
wasip3 = "0.2.0"
#async-std = { workspace = true, features = ["attributes"] }
tokio = { version = "1.15.0", features = ["sync", "macros", "io-util", "rt", "time"] }
dotenvy = "0.15.0"
trybuild = "1.0.53"
sqlx-test = { path = "./sqlx-test" }
Expand All @@ -234,8 +242,8 @@ url = "2.2.2"
rand = "0.8.4"
rand_xoshiro = "0.6.0"
hex = "0.4.3"
tempfile = "3.10.1"
criterion = { version = "0.5.1", features = ["async_tokio"] }
#tempfile = "3.10.1"
#criterion = { version = "0.5.1", features = ["async_tokio"] }
libsqlite3-sys = { version = "0.30.1" }

# If this is an unconditional dev-dependency then Cargo will *always* try to build `libsqlite3-sys`,
Expand All @@ -253,6 +261,9 @@ cast_sign_loss = 'deny'
# See `clippy.toml`
disallowed_methods = 'deny'

[patch.crates-io]
whoami = { git = "https://github.com/Aditya1404Sal/whoami", branch = "v2" }


[lints.rust.unexpected_cfgs]
level = 'warn'
Expand Down Expand Up @@ -360,6 +371,10 @@ name = "mysql"
path = "tests/mysql/mysql.rs"
required-features = ["mysql"]

[[test]]
name = "wasi_integration_test"
path = "tests/mysql/wasi_integration_test.rs"

[[test]]
name = "mysql-types"
path = "tests/mysql/types.rs"
Expand Down
13 changes: 11 additions & 2 deletions examples/mysql/todos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@ version = "0.1.0"
edition = "2021"
workspace = "../../../"

[lib]
crate-type = ["cdylib"]

[dependencies]
anyhow = "1.0"
sqlx = { path = "../../../", features = [ "mysql", "runtime-tokio", "tls-native-tls" ] }
futures = "0.3"
sqlx = { path = "../../../", features = [ "mysql", "runtime-tokio" ] }
clap = { version = "4", features = ["derive"] }
tokio = { version = "1.20.0", features = ["rt", "macros"]}
tokio = { version = "1.20.0", features = ["rt"]}
dotenvy = "0.15.0"
wasip3 = "0.2.0+wasi-0.3.0-rc-2025-09-16"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
sqlx = { path = "../../../", features = ["tls-native-tls"] }
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,26 @@ enum Command {
Done { id: u64 },
}

#[tokio::main(flavor = "current_thread")]
async fn main() -> anyhow::Result<()> {
let args = Args::parse();
async fn run() -> anyhow::Result<()> {
let args = Args::parse_from(wasip3::cli::environment::get_arguments());
let pool = MySqlPool::connect(&env::var("DATABASE_URL")?).await?;

match args.cmd {
Some(Command::Add { description }) => {
println!("Adding new todo with description '{description}'");
eprintln!("Adding new todo with description '{description}'");
let todo_id = add_todo(&pool, description).await?;
println!("Added new todo with id {todo_id}");
eprintln!("Added new todo with id {todo_id}");
}
Some(Command::Done { id }) => {
println!("Marking todo {id} as done");
eprintln!("Marking todo {id} as done");
if complete_todo(&pool, id).await? {
println!("Todo {id} is marked as done");
eprintln!("Todo {id} is marked as done");
} else {
println!("Invalid id {id}");
eprintln!("Invalid id {id}");
}
}
None => {
println!("Printing list of all todos");
eprintln!("Printing list of all todos");
list_todos(&pool).await?;
}
}
Expand All @@ -43,7 +42,6 @@ async fn main() -> anyhow::Result<()> {
}

async fn add_todo(pool: &MySqlPool, description: String) -> anyhow::Result<u64> {
// Insert the task, then obtain the ID of this row
let todo_id = sqlx::query!(
r#"
INSERT INTO todos ( description )
Expand Down Expand Up @@ -85,10 +83,8 @@ ORDER BY id
.fetch_all(pool)
.await?;

// NOTE: Booleans in MySQL are stored as `TINYINT(1)` / `i8`
// 0 = false, non-0 = true
for rec in recs {
println!(
eprintln!(
"- [{}] {}: {}",
if rec.done != 0 { "x" } else { " " },
rec.id,
Expand All @@ -98,3 +94,31 @@ ORDER BY id

Ok(())
}

wasip3::cli::command::export!(Component);

struct Component;

impl wasip3::exports::cli::run::Guest for Component {
async fn run() -> Result<(), ()> {
tokio::task::LocalSet::new()
.run_until(async {
if let Err(err) = run().await {
let (mut tx, rx) = wasip3::wit_stream::new();

futures::join!(
async { wasip3::cli::stderr::write_via_stream(rx).await.unwrap() },
async {
let remaining = tx.write_all(format!("{err:#}\n").into_bytes()).await;
assert!(remaining.is_empty());
drop(tx);
}
);
Err(())
} else {
Ok(())
}
})
.await
}
}
22 changes: 18 additions & 4 deletions sqlx-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ _unstable-doc = ["sqlx-toml"]
async-global-executor = { workspace = true, optional = true }
async-std = { workspace = true, optional = true }
smol = { workspace = true, optional = true }
tokio = { workspace = true, optional = true }
tokio = { workspace = true, optional = true, features = ["sync","rt"]}
tokio-util = { workspace = true }
async-lock = "2.5.0"
once_cell = "1.21.3"

# TLS
native-tls = { version = "0.2.10", optional = true }
Expand Down Expand Up @@ -81,6 +84,7 @@ chrono = { version = "0.4.34", default-features = false, features = ["clock"], o
crc = { version = "3", optional = true }
crossbeam-queue = "0.3.2"
either = "1.6.1"
futures = "0.3"
futures-core = { version = "0.3.19", default-features = false }
futures-io = "0.3.24"
futures-intrusive = "0.5.0"
Expand All @@ -94,18 +98,28 @@ toml = { version = "0.8.16", optional = true }
sha2 = { version = "0.10.0", default-features = false, optional = true }
#sqlformat = "0.2.0"
thiserror = "2.0.0"
tokio-stream = { version = "0.1.8", features = ["fs"], optional = true }
tokio-stream = { version = "0.1.8", optional = true }
tracing = { version = "0.1.37", features = ["log"] }
smallvec = "1.7.0"
url = { version = "2.2.2" }
bstr = { version = "1.0", default-features = false, features = ["std"], optional = true }
hashlink = "0.10.0"
indexmap = "2.0"
event-listener = "5.2.0"
hashbrown = "0.15.0"
hashbrown = { version = "0.15.0", default-features = false }
[target.'cfg(target_arch = "wasm32")'.dependencies]
tokio = { workspace = true, features = ["sync", "rt"] }
tokio-util = { workspace = true }
wasip3 = { workspace = true }
wit-bindgen = { workspace = true, optional = true }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio = { workspace = true, features = ["net", "fs"], optional = true }
tokio-stream = { version = "0.1.8", features = ["fs"], optional = true }


[dev-dependencies]
sqlx = { workspace = true, features = ["postgres", "sqlite", "mysql", "migrate", "macros", "time", "uuid"] }
sqlx = { workspace = true, features = ["mysql", "migrate", "macros", "time", "uuid"] }
tokio = { version = "1", features = ["rt"] }

[lints]
Expand Down
Loading