Client Connection

Provides a set of functions that establish connections, execute queries and manage data transactions with different databases.

Independent benchmarks are available at https://github.com/diesel-rs/metrics.

PostgreSQL

Implements a subset of https://www.postgresql.org/docs/16/protocol.html. PostgreSQL is a robust, open-source relational database management system that, among other things, supports several data types and usually also excels in concurrent scenarios.

To use this functionality, it is necessary to activate the postgres feature.

PostgreSQL Benchmark

Example

//! Demonstrates different interactions with a PostgreSQL database. //! //! This snippet requires ~40 dependencies and has an optimized binary size of ~600K. extern crate tokio; extern crate wtx; extern crate wtx_instances; use wtx::database::{Executor as _, Record, Records}; #[tokio::main] async fn main() -> wtx::Result<()> { let uri = "postgres://USER:PASSWORD@localhost/DATABASE"; let mut executor = wtx_instances::executor_postgres(&uri).await?; executor .transaction(|this| async { this.execute("CREATE TABLE IF NOT EXISTS example(id INT, name VARCHAR)", |_| Ok(())).await?; this .execute_with_stmt("INSERT INTO foo VALUES ($1, $2), ($3, $4)", (1u32, "one", 2u32, "two")) .await?; Ok(((), this)) }) .await?; let records = executor .fetch_many_with_stmt("SELECT id, name FROM example", (), |_| Ok::<_, wtx::Error>(())) .await?; assert_eq!(records.get(0).as_ref().and_then(|record| record.decode("id").ok()), Some(1)); assert_eq!(records.get(1).as_ref().and_then(|record| record.decode("name").ok()), Some("two")); Ok(()) }

MySQL

Implements a subset of https://dev.mysql.com/doc/dev/mysql-server/latest/. MySQL is also a robust, open-source relational database management system generally used in web applications.

WTX includes CI coverage for MariaDB and Percona, as such, interactions with these MySQL-based databases shouldn't be a problem.

To use this functionality, it is necessary to activate the mysql feature.

Example

//! Demonstrates a MySQL query. //! //! This snippet requires ~40 dependencies and has an optimized binary size of ~600K. extern crate tokio; extern crate wtx; extern crate wtx_instances; use wtx::database::{Executor as _, Record, Records}; #[tokio::main] async fn main() -> wtx::Result<()> { let uri = "mysql://USER:PASSWORD@localhost/DATABASE"; let mut executor = wtx_instances::executor_mysql(&uri).await?; let records = executor .fetch_many_with_stmt("SELECT id, name FROM example", (), |_| Ok::<_, wtx::Error>(())) .await?; assert_eq!(records.get(0).as_ref().and_then(|record| record.decode("id").ok()), Some(1)); assert_eq!(records.get(1).as_ref().and_then(|record| record.decode("name").ok()), Some("two")); Ok(()) }