From b50dc782000b028818528ec31b96b423d9a26008 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Sat, 8 Jul 2023 23:51:34 +0100 Subject: [PATCH] update mysql dependency to 24 --- .github/workflows/ci.yml | 14 +++----------- CHANGELOG.md | 12 ++++++++++++ Cargo.toml | 4 ++-- README.md | 19 +++++++++++-------- examples/basic.rs | 34 ++++++++++++++++++++++++++++++++++ src/lib.rs | 9 +++++---- src/pool.rs | 4 ---- 7 files changed, 67 insertions(+), 29 deletions(-) create mode 100644 CHANGELOG.md create mode 100644 examples/basic.rs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5972628..7578280 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,21 +16,13 @@ jobs: name: tests / ${{ matrix.version }} runs-on: ubuntu-latest - env: - CI: 1 - CARGO_UNSTABLE_SPARSE_REGISTRY: true - steps: - uses: actions/checkout@v3 - name: Install Rust - run: | - rustup install ${{ matrix.version }} --no-self-update --profile minimal --force - rustup override set ${{ matrix.version }} - - - run: cargo generate-lockfile - - name: Cache Dependencies - uses: Swatinem/rust-cache@v2.2.0 + uses: actions-rust-lang/setup-rust-toolchain@v1.5.0 + with: + toolchain: ${{ matrix.version }} - name: Setup MySQL uses: mirromutth/mysql-action@v1.1 diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..8462831 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,12 @@ +# Changelog + +## Unreleased + +## 24.0.0 + +- Update `mysql` dependency to `24`. +- Remove deprecated `MysqlConnectionManager` type alias. + +## 23.0.0 + +- Update `mysql` dependency to `23`. diff --git a/Cargo.toml b/Cargo.toml index 52a484c..fefb0e3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "r2d2_mysql" -version = "23.0.0" +version = "24.0.0" authors = ["outersky "] license = "MIT" description = "MySQL support for the r2d2 connection pool" @@ -10,4 +10,4 @@ edition = "2018" [dependencies] r2d2 = "0.8.9" -mysql = "23" +mysql = "24" diff --git a/README.md b/README.md index a423c16..6e04034 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ -# r2d2-mysql +# r2d2_mysql > [`mysql`](https://github.com/blackbeam/rust-mysql-simple) support library for the [`r2d2`](https://github.com/sfackler/r2d2) connection pool. -[![crates.io](https://img.shields.io/crates/v/r2d2-mysql?label=latest)](https://crates.io/crates/r2d2-mysql) -[![Documentation](https://docs.rs/r2d2-mysql/badge.svg?version=23)](https://docs.rs/r2d2-mysql/23) +[![crates.io](https://img.shields.io/crates/v/r2d2_mysql?label=latest)](https://crates.io/crates/r2d2_mysql) +[![Documentation](https://docs.rs/r2d2_mysql/badge.svg?version=24)](https://docs.rs/r2d2_mysql/24) ![Version](https://img.shields.io/badge/rustc-1.59+-ab6000.svg) -![License](https://img.shields.io/crates/l/r2d2-mysql.svg) -[![Download](https://img.shields.io/crates/d/r2d2-mysql.svg)](https://crates.io/crates/r2d2-mysql) +![License](https://img.shields.io/crates/l/r2d2_mysql.svg) +[![Download](https://img.shields.io/crates/d/r2d2_mysql.svg)](https://crates.io/crates/r2d2_mysql) ## Install @@ -14,15 +14,18 @@ Include `r2d2_mysql` in the `[dependencies]` section of your `Cargo.toml`: ```toml [dependencies] -r2d2_mysql = "23" +r2d2_mysql = "24" ``` ## Usage ```rust use std::{env, sync::Arc, thread}; -use mysql::{prelude::*, Opts, OptsBuilder}; -use r2d2_mysql::MySqlConnectionManager; + +use r2d2_mysql::{ + mysql::{prelude::*, Opts, OptsBuilder}, + r2d2, MySqlConnectionManager, +}; fn main() { let url = env::var("DATABASE_URL").unwrap(); diff --git a/examples/basic.rs b/examples/basic.rs new file mode 100644 index 0000000..5377f64 --- /dev/null +++ b/examples/basic.rs @@ -0,0 +1,34 @@ +use std::{env, sync::Arc, thread}; + +use r2d2_mysql::{ + mysql::{prelude::*, Opts, OptsBuilder}, + r2d2, MySqlConnectionManager, +}; + +fn main() { + let url = env::var("DATABASE_URL").unwrap(); + let opts = Opts::from_url(&url).unwrap(); + let builder = OptsBuilder::from_opts(opts); + let manager = MySqlConnectionManager::new(builder); + let pool = Arc::new(r2d2::Pool::builder().max_size(4).build(manager).unwrap()); + + let mut tasks = vec![]; + + for _ in 0..3 { + let pool = pool.clone(); + let th = thread::spawn(move || { + let mut conn = pool.get().expect("error getting connection from pool"); + + let _ = conn + .query("SELECT version()") + .map(|rows: Vec| rows.is_empty()) + .expect("error executing query"); + }); + + tasks.push(th); + } + + for th in tasks { + let _ = th.join(); + } +} diff --git a/src/lib.rs b/src/lib.rs index 626fe65..41e247f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,8 +3,11 @@ //! # Examples //! ``` //! use std::{env, sync::Arc, thread}; -//! use mysql::{prelude::*, Opts, OptsBuilder}; -//! use r2d2_mysql::MySqlConnectionManager; +//! +//! use r2d2_mysql::{ +//! mysql::{prelude::*, Opts, OptsBuilder}, +//! r2d2, MySqlConnectionManager, +//! }; //! //! let url = env::var("DATABASE_URL").unwrap(); //! let opts = Opts::from_url(&url).unwrap(); @@ -38,8 +41,6 @@ pub use r2d2; mod pool; pub use self::pool::MySqlConnectionManager; -#[allow(deprecated)] -pub use self::pool::MysqlConnectionManager; #[cfg(test)] mod test { diff --git a/src/pool.rs b/src/pool.rs index e35dcf6..b875a17 100644 --- a/src/pool.rs +++ b/src/pool.rs @@ -4,10 +4,6 @@ use mysql::{error::Error, prelude::*, Conn, Opts, OptsBuilder}; -#[doc(hidden)] -#[deprecated(since = "23.0.0", note = "Renamed to `MySqlConnectionManager`.")] -pub type MysqlConnectionManager = MySqlConnectionManager; - /// An [`r2d2`] connection manager for [`mysql`] connections. #[derive(Clone, Debug)] pub struct MySqlConnectionManager {