tokio-rusqlite-0.6.0/.cargo_vcs_info.json0000644000000001360000000000100140320ustar { "git": { "sha1": "168e9c47fd6c7c9f8032b660f62084e16ade7bac" }, "path_in_vcs": "" }tokio-rusqlite-0.6.0/.github/CODEOWNERS000064400000000000000000000000351046102023000155530ustar 00000000000000* @programatik29 * @abs0luty tokio-rusqlite-0.6.0/.github/dependabot.yml000064400000000000000000000001771046102023000170170ustar 00000000000000version: 2 updates: - package-ecosystem: cargo directory: "/" schedule: interval: daily open-pull-requests-limit: 10 tokio-rusqlite-0.6.0/.github/workflows/ci.yml000064400000000000000000000053611046102023000173420ustar 00000000000000on: [push, pull_request] name: Test and coverage env: CARGO_TERM_COLOR: always jobs: check: name: Check runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions-rs/toolchain@v1 with: profile: minimal toolchain: stable override: true - uses: actions-rs/cargo@v1 with: command: check test_no_features: name: Test no features runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions-rs/toolchain@v1 with: profile: minimal toolchain: stable override: true - uses: actions-rs/cargo@v1 with: command: test test_all_features: name: Test all features runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions-rs/toolchain@v1 with: profile: minimal toolchain: stable override: true - uses: actions-rs/cargo@v1 with: command: test args: --all-features fmt: name: Rustfmt runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions-rs/toolchain@v1 with: profile: minimal toolchain: stable override: true - run: rustup component add rustfmt - uses: actions-rs/cargo@v1 with: command: fmt args: --all -- --check mutation-tests: name: Mutation tests runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions-rs/toolchain@v1 with: profile: minimal toolchain: stable override: true - uses: Swatinem/rust-cache@v2 - run: cargo install cargo-mutants - uses: actions-rs/cargo@v1 with: command: mutants clippy: name: Clippy runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions-rs/toolchain@v1 with: profile: minimal toolchain: stable override: true - uses: Swatinem/rust-cache@v2 - run: rustup component add clippy - uses: actions-rs/cargo@v1 with: command: clippy args: -- -D warnings coverage: name: Code coverage runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions-rs/toolchain@v1 with: profile: minimal toolchain: stable override: true - uses: Swatinem/rust-cache@v2 - run: cargo install cargo-tarpaulin - name: Generate code coverage uses: actions-rs/cargo@v1 with: command: tarpaulin args: --verbose --all-features --run-types AllTargets --workspace --timeout 120 --out Lcov tokio-rusqlite-0.6.0/.gitignore000064400000000000000000000000241046102023000146060ustar 00000000000000/target /Cargo.lock tokio-rusqlite-0.6.0/CHANGELOG.md000064400000000000000000000034021046102023000144320ustar 00000000000000# Changelog All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog], and this project adheres to [Semantic Versioning]. # Unreleased Nothing. # 0.6.0 (20 Sep 2024) - **updated**: [rusqlite] version to `0.32`. - **added**: `bundled` feature corresponding to `rusqlite/bundled` feature. - **added**: Implement `From` for `Connection`. - **removed**: async `Connection::from` implementation instead added above. # 0.5.1 (13 Feb 2024) - **updated:** To latest [rusqlite] version (`0.31`). - **added**: Reexported all names from `rusqlite` crate. # 0.5.0 (25 Nov 2023) - **updated:** To latest [rusqlite] version (`0.30`). - **added:** Added `params` macro export from `rusqlite` crate. - **breaking:** `Connection::call` now takes `tokio_rusqlite::Result` instead of `rusqlite::Result`. - **added:** Added `Error::Other` variant for application specific errors. - **added:** Added `Connection::call_unwrap` method. # 0.4.0 (3 April 2023) - **added:** Added `Connection::close` method. - **added:** Added `tokio_rusqlite::Error` type. - **breaking:** All `Connection` methods now return `Result<_, tokio_rusqlite::Error>`. - **updated:** To latest [rusqlite] version (`0.29`). # 0.3.0 (16 Sep 2022) - **updated:** To latest [rusqlite] version (`0.28`). # 0.2.0 (13 July 2022) - **changed:** Now using unbounded `crossbeam-channel` instead of bounded `std::sync::mpsc` channel internally. - **changed:** Channel send errors in background database thread are now ignored instead of panicking. # 0.1.0 (25 April 2022) - Initial release. [rusqlite]: https://crates.io/crates/rusqlite [Keep a Changelog]: https://keepachangelog.com/en/1.0.0/ [Semantic Versioning]: https://semver.org/spec/v2.0.0.html tokio-rusqlite-0.6.0/Cargo.lock0000644000000320240000000000100120060ustar # This file is automatically @generated by Cargo. # It is not intended for manual editing. version = 3 [[package]] name = "ahash" version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ "cfg-if", "once_cell", "version_check", "zerocopy", ] [[package]] name = "autocfg" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "bytes" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" [[package]] name = "cc" version = "1.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "07b1695e2c7e8fc85310cde85aeaab7e3097f593c91d209d3f9df76c928100f0" dependencies = [ "shlex", ] [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "crossbeam-channel" version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5aaa7bd5fb665c6864b5f963dd9097905c54125909c7aa94c9e18507cdbe6c53" dependencies = [ "cfg-if", "crossbeam-utils", ] [[package]] name = "crossbeam-utils" version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0bf124c720b7686e3c2663cf54062ab0f68a88af2fb6a030e87e30bf721fcb38" dependencies = [ "cfg-if", "lazy_static", ] [[package]] name = "fallible-iterator" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2acce4a10f12dc2fb14a218589d4f1f62ef011b2d0cc4b3cb1bba8e94da14649" [[package]] name = "fallible-streaming-iterator" version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a" [[package]] name = "hashbrown" version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" dependencies = [ "ahash", ] [[package]] name = "hashlink" version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ba4ff7128dee98c7dc9794b6a411377e1404dba1c97deb8d1a55297bd25d8af" dependencies = [ "hashbrown", ] [[package]] name = "hermit-abi" version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" dependencies = [ "libc", ] [[package]] name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" version = "0.2.124" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "21a41fed9d98f27ab1c6d161da622a4fa35e8a54a8adc24bbf3ddd0ef70b0e50" [[package]] name = "libsqlite3-sys" version = "0.30.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2e99fb7a497b1e3339bc746195567ed8d3e24945ecd636e3619d20b9de9e9149" dependencies = [ "cc", "pkg-config", "vcpkg", ] [[package]] name = "lock_api" version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16" dependencies = [ "autocfg", "scopeguard", ] [[package]] name = "log" version = "0.4.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4" [[package]] name = "memchr" version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "mio" version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" dependencies = [ "libc", "log", "wasi", "windows-sys", ] [[package]] name = "num_cpus" version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" dependencies = [ "hermit-abi", "libc", ] [[package]] name = "once_cell" version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "parking_lot" version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" dependencies = [ "lock_api", "parking_lot_core", ] [[package]] name = "parking_lot_core" version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447" dependencies = [ "cfg-if", "libc", "redox_syscall", "smallvec", "windows-targets", ] [[package]] name = "pin-project-lite" version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e280fbe77cc62c91527259e9442153f4688736748d24660126286329742b4c6c" [[package]] name = "pkg-config" version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" [[package]] name = "proc-macro2" version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] [[package]] name = "quote" version = "1.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b9ab9c7eadfd8df19006f1cf1a4aed13540ed5cbc047010ece5826e10825488" dependencies = [ "proc-macro2", ] [[package]] name = "redox_syscall" version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" dependencies = [ "bitflags 1.3.2", ] [[package]] name = "rusqlite" version = "0.32.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7753b721174eb8ff87a9a0e799e2d7bc3749323e773db92e0984debb00019d6e" dependencies = [ "bitflags 2.6.0", "fallible-iterator", "fallible-streaming-iterator", "hashlink", "libsqlite3-sys", "smallvec", ] [[package]] name = "scopeguard" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "shlex" version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "signal-hook-registry" version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" dependencies = [ "libc", ] [[package]] name = "smallvec" version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" [[package]] name = "socket2" version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd" dependencies = [ "libc", "winapi", ] [[package]] name = "syn" version = "1.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] [[package]] name = "syn" version = "2.0.43" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee659fb5f3d355364e1f3e5bc10fb82068efbf824a1e9d1c9504244a6469ad53" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] [[package]] name = "tokio" version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2af73ac49756f3f7c01172e34a23e5d0216f6c32333757c2c61feb2bbff5a5ee" dependencies = [ "bytes", "libc", "memchr", "mio", "num_cpus", "once_cell", "parking_lot", "pin-project-lite", "signal-hook-registry", "socket2", "tokio-macros", "winapi", ] [[package]] name = "tokio-macros" version = "1.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8" dependencies = [ "proc-macro2", "quote", "syn 1.0.109", ] [[package]] name = "tokio-rusqlite" version = "0.6.0" dependencies = [ "crossbeam-channel", "rusqlite", "tokio", ] [[package]] name = "unicode-ident" version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b15811caf2415fb889178633e7724bad2509101cde276048e013b9def5e51fa0" [[package]] name = "vcpkg" version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" [[package]] name = "version_check" version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "winapi" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" dependencies = [ "winapi-i686-pc-windows-gnu", "winapi-x86_64-pc-windows-gnu", ] [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows-sys" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ "windows-targets", ] [[package]] name = "windows-targets" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", "windows_i686_gnu", "windows_i686_msvc", "windows_x86_64_gnu", "windows_x86_64_gnullvm", "windows_x86_64_msvc", ] [[package]] name = "windows_aarch64_gnullvm" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" [[package]] name = "windows_aarch64_msvc" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" [[package]] name = "windows_i686_gnu" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" [[package]] name = "windows_i686_msvc" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" [[package]] name = "windows_x86_64_gnu" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" [[package]] name = "windows_x86_64_gnullvm" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" [[package]] name = "windows_x86_64_msvc" version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" [[package]] name = "zerocopy" version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", "syn 2.0.43", ] tokio-rusqlite-0.6.0/Cargo.toml0000644000000031250000000000100120310ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2021" name = "tokio-rusqlite" version = "0.6.0" authors = [ "Programatik ", "Adi Salimgereev ", ] build = false autobins = false autoexamples = false autotests = false autobenches = false description = "Asynchronous handle for rusqlite library." homepage = "https://github.com/programatik29/tokio-rusqlite" documentation = "https://docs.rs/tokio-rusqlite" readme = "README.md" keywords = [ "async", "rusqlite", "sqlite", ] categories = [ "asynchronous", "database", ] license = "MIT" repository = "https://github.com/programatik29/tokio-rusqlite" [lib] name = "tokio_rusqlite" path = "src/lib.rs" [[example]] name = "in_memory" path = "examples/in_memory.rs" [[example]] name = "multiple_tasks" path = "examples/multiple_tasks.rs" [dependencies.crossbeam-channel] version = "0.5" [dependencies.rusqlite] version = "0.32" [dependencies.tokio] version = "1" features = ["sync"] [dev-dependencies.rusqlite] version = "0.32" features = ["bundled"] [dev-dependencies.tokio] version = "1" features = ["full"] [features] bundled = ["rusqlite/bundled"] tokio-rusqlite-0.6.0/Cargo.toml.orig000064400000000000000000000014041046102023000155100ustar 00000000000000[package] name = "tokio-rusqlite" version = "0.6.0" authors = ["Programatik ", "Adi Salimgereev "] edition = "2021" description = "Asynchronous handle for rusqlite library." documentation = "https://docs.rs/tokio-rusqlite" homepage = "https://github.com/programatik29/tokio-rusqlite" repository = "https://github.com/programatik29/tokio-rusqlite" license = "MIT" keywords = ["async", "rusqlite", "sqlite"] categories = ["asynchronous", "database"] [features] bundled = ["rusqlite/bundled"] [dependencies] crossbeam-channel = "0.5" rusqlite = "0.32" tokio = { version = "1", features = ["sync"] } [dev-dependencies] rusqlite = { version = "0.32", features = ["bundled"] } tokio = { version = "1", features = ["full"] } tokio-rusqlite-0.6.0/LICENSE000064400000000000000000000020341046102023000136260ustar 00000000000000Copyright 2022 Eray Karatay Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. tokio-rusqlite-0.6.0/README.md000064400000000000000000000040201046102023000140750ustar 00000000000000[![License](https://img.shields.io/crates/l/tokio-rusqlite)](https://choosealicense.com/licenses/mit/) [![Crates.io](https://img.shields.io/crates/v/tokio-rusqlite)](https://crates.io/crates/tokio-rusqlite) [![Docs - Stable](https://img.shields.io/crates/v/tokio-rusqlite?color=blue&label=docs)](https://docs.rs/tokio-rusqlite/) # tokio-rusqlite Asynchronous handle for rusqlite library. # Usage ```rust use tokio_rusqlite::{params, Connection, Result}; #[derive(Debug)] struct Person { id: i32, name: String, data: Option>, } #[tokio::main] async fn main() -> Result<()> { let conn = Connection::open_in_memory().await?; let people = conn .call(|conn| { conn.execute( "CREATE TABLE person ( id INTEGER PRIMARY KEY, name TEXT NOT NULL, data BLOB )", [], )?; let steven = Person { id: 1, name: "Steven".to_string(), data: None, }; conn.execute( "INSERT INTO person (name, data) VALUES (?1, ?2)", params![steven.name, steven.data], )?; let mut stmt = conn.prepare("SELECT id, name, data FROM person")?; let people = stmt .query_map([], |row| { Ok(Person { id: row.get(0)?, name: row.get(1)?, data: row.get(2)?, }) })? .collect::, rusqlite::Error>>()?; Ok(people) }) .await?; for person in people { println!("Found person {person:?}"); } conn.close().await?; Ok(()) } ``` # Safety This crate uses `#![forbid(unsafe_code)]` to ensure everything is implemented in 100% safe Rust. # License This project is licensed under the [MIT license](./LICENSE). tokio-rusqlite-0.6.0/examples/in_memory.rs000064400000000000000000000026651046102023000170150ustar 00000000000000#![allow(dead_code)] use tokio_rusqlite::{params, Connection, Result}; #[derive(Debug)] struct Person { id: i32, name: String, data: Option>, } #[tokio::main] async fn main() -> Result<()> { let conn = Connection::open_in_memory().await?; let people = conn .call(|conn| { conn.execute( "CREATE TABLE person ( id INTEGER PRIMARY KEY, name TEXT NOT NULL, data BLOB )", [], )?; let steven = Person { id: 1, name: "Steven".to_string(), data: None, }; conn.execute( "INSERT INTO person (name, data) VALUES (?1, ?2)", params![steven.name, steven.data], )?; let mut stmt = conn.prepare("SELECT id, name, data FROM person")?; let people = stmt .query_map([], |row| { Ok(Person { id: row.get(0)?, name: row.get(1)?, data: row.get(2)?, }) })? .collect::, rusqlite::Error>>()?; Ok(people) }) .await?; for person in people { println!("Found person {person:?}"); } conn.close().await?; Ok(()) } tokio-rusqlite-0.6.0/examples/multiple_tasks.rs000064400000000000000000000046531046102023000200560ustar 00000000000000#![allow(dead_code)] use tokio::task::JoinHandle; use tokio_rusqlite::{params, Connection, Result}; #[derive(Debug)] struct Person { id: i32, name: String, data: Option>, } #[tokio::main] async fn main() -> Result<()> { let conn = Connection::open_in_memory().await?; // Create table. conn.call(|conn| { conn.execute( "CREATE TABLE person ( id INTEGER PRIMARY KEY, name TEXT NOT NULL, data BLOB )", [], ) .map_err(|e| e.into()) }) .await?; // Start tasks. let add_steven = add_steven_task(conn.clone()); let add_bob = add_bob_task(conn.clone()); // Wait for tasks to finish. add_steven.await.unwrap(); add_bob.await.unwrap(); // Select inserted data and collect results. let people = conn .call(|conn| { let mut stmt = conn.prepare("SELECT id, name, data FROM person")?; let people = stmt .query_map([], |row| { Ok(Person { id: row.get(0)?, name: row.get(1)?, data: row.get(2)?, }) })? .collect::, rusqlite::Error>>()?; Ok(people) }) .await?; for person in people { println!("Found person {person:?}"); } conn.close().await?; Ok(()) } fn add_steven_task(conn: Connection) -> JoinHandle<()> { tokio::spawn(async move { let steven = Person { id: 0, name: "Steven".to_string(), data: None, }; conn.call(move |conn| { conn.execute( "INSERT INTO person (name, data) VALUES (?1, ?2)", params![steven.name, steven.data], ) .map_err(|e| e.into()) }) .await .unwrap(); }) } fn add_bob_task(conn: Connection) -> JoinHandle<()> { tokio::spawn(async move { let bob = Person { id: 0, name: "Bob".to_string(), data: None, }; conn.call(move |conn| { conn.execute( "INSERT INTO person (name, data) VALUES (?1, ?2)", params![bob.name, bob.data], ) .map_err(|e| e.into()) }) .await .unwrap(); }) } tokio-rusqlite-0.6.0/src/lib.rs000064400000000000000000000324271046102023000145350ustar 00000000000000//! Asynchronous handle for rusqlite library. //! //! # Guide //! //! This library provides [`Connection`] struct. [`Connection`] struct is a handle //! to call functions in background thread and can be cloned cheaply. //! [`Connection::call`] method calls provided function in the background thread //! and returns its result asynchronously. //! //! # Design //! //! A thread is spawned for each opened connection handle. When `call` method //! is called: provided function is boxed, sent to the thread through mpsc //! channel and executed. Return value is then sent by oneshot channel from //! the thread and then returned from function. //! //! # Example //! //! ```rust,no_run //! use tokio_rusqlite::{params, Connection, Result}; //! //! #[derive(Debug)] //! struct Person { //! id: i32, //! name: String, //! data: Option>, //! } //! //! #[tokio::main] //! async fn main() -> Result<()> { //! let conn = Connection::open_in_memory().await?; //! //! let people = conn //! .call(|conn| { //! conn.execute( //! "CREATE TABLE person ( //! id INTEGER PRIMARY KEY, //! name TEXT NOT NULL, //! data BLOB //! )", //! [], //! )?; //! //! let steven = Person { //! id: 1, //! name: "Steven".to_string(), //! data: None, //! }; //! //! conn.execute( //! "INSERT INTO person (name, data) VALUES (?1, ?2)", //! params![steven.name, steven.data], //! )?; //! //! let mut stmt = conn.prepare("SELECT id, name, data FROM person")?; //! let people = stmt //! .query_map([], |row| { //! Ok(Person { //! id: row.get(0)?, //! name: row.get(1)?, //! data: row.get(2)?, //! }) //! })? //! .collect::, rusqlite::Error>>()?; //! //! Ok(people) //! }) //! .await?; //! //! for person in people { //! println!("Found person {:?}", person); //! } //! //! Ok(()) //! } //! ``` #![forbid(unsafe_code)] #![warn( clippy::await_holding_lock, clippy::cargo_common_metadata, clippy::dbg_macro, clippy::empty_enum, clippy::enum_glob_use, clippy::inefficient_to_string, clippy::mem_forget, clippy::mutex_integer, clippy::needless_continue, clippy::todo, clippy::unimplemented, clippy::wildcard_imports, future_incompatible, missing_docs, missing_debug_implementations, unreachable_pub )] #[cfg(test)] mod tests; use crossbeam_channel::{Receiver, Sender}; use std::{ fmt::{self, Debug, Display}, path::Path, thread, }; use tokio::sync::oneshot::{self}; pub use rusqlite::*; const BUG_TEXT: &str = "bug in tokio-rusqlite, please report"; #[derive(Debug)] /// Represents the errors specific for this library. #[non_exhaustive] pub enum Error { /// The connection to the SQLite has been closed and cannot be queried any more. ConnectionClosed, /// An error occured while closing the SQLite connection. /// This `Error` variant contains the [`Connection`], which can be used to retry the close operation /// and the underlying [`rusqlite::Error`] that made it impossile to close the database. Close((Connection, rusqlite::Error)), /// A `Rusqlite` error occured. Rusqlite(rusqlite::Error), /// An application-specific error occured. Other(Box), } impl Display for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Error::ConnectionClosed => write!(f, "ConnectionClosed"), Error::Close((_, e)) => write!(f, "Close((Connection, \"{e}\"))"), Error::Rusqlite(e) => write!(f, "Rusqlite(\"{e}\")"), Error::Other(ref e) => write!(f, "Other(\"{e}\")"), } } } impl std::error::Error for Error { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { match self { Error::ConnectionClosed => None, Error::Close((_, e)) => Some(e), Error::Rusqlite(e) => Some(e), Error::Other(ref e) => Some(&**e), } } } impl From for Error { fn from(value: rusqlite::Error) -> Self { Error::Rusqlite(value) } } /// The result returned on method calls in this crate. pub type Result = std::result::Result; type CallFn = Box; enum Message { Execute(CallFn), Close(oneshot::Sender>), } /// A handle to call functions in background thread. #[derive(Clone)] pub struct Connection { sender: Sender, } impl Connection { /// Open a new connection to a SQLite database. /// /// `Connection::open(path)` is equivalent to /// `Connection::open_with_flags(path, OpenFlags::SQLITE_OPEN_READ_WRITE | /// OpenFlags::SQLITE_OPEN_CREATE)`. /// /// # Failure /// /// Will return `Err` if `path` cannot be converted to a C-compatible /// string or if the underlying SQLite open call fails. pub async fn open>(path: P) -> Result { let path = path.as_ref().to_owned(); start(move || rusqlite::Connection::open(path)) .await .map_err(Error::Rusqlite) } /// Open a new connection to an in-memory SQLite database. /// /// # Failure /// /// Will return `Err` if the underlying SQLite open call fails. pub async fn open_in_memory() -> Result { start(rusqlite::Connection::open_in_memory) .await .map_err(Error::Rusqlite) } /// Open a new connection to a SQLite database. /// /// [Database Connection](http://www.sqlite.org/c3ref/open.html) for a /// description of valid flag combinations. /// /// # Failure /// /// Will return `Err` if `path` cannot be converted to a C-compatible /// string or if the underlying SQLite open call fails. pub async fn open_with_flags>(path: P, flags: OpenFlags) -> Result { let path = path.as_ref().to_owned(); start(move || rusqlite::Connection::open_with_flags(path, flags)) .await .map_err(Error::Rusqlite) } /// Open a new connection to a SQLite database using the specific flags /// and vfs name. /// /// [Database Connection](http://www.sqlite.org/c3ref/open.html) for a /// description of valid flag combinations. /// /// # Failure /// /// Will return `Err` if either `path` or `vfs` cannot be converted to a /// C-compatible string or if the underlying SQLite open call fails. pub async fn open_with_flags_and_vfs>( path: P, flags: OpenFlags, vfs: &str, ) -> Result { let path = path.as_ref().to_owned(); let vfs = vfs.to_owned(); start(move || rusqlite::Connection::open_with_flags_and_vfs(path, flags, &vfs)) .await .map_err(Error::Rusqlite) } /// Open a new connection to an in-memory SQLite database. /// /// [Database Connection](http://www.sqlite.org/c3ref/open.html) for a /// description of valid flag combinations. /// /// # Failure /// /// Will return `Err` if the underlying SQLite open call fails. pub async fn open_in_memory_with_flags(flags: OpenFlags) -> Result { start(move || rusqlite::Connection::open_in_memory_with_flags(flags)) .await .map_err(Error::Rusqlite) } /// Open a new connection to an in-memory SQLite database using the /// specific flags and vfs name. /// /// [Database Connection](http://www.sqlite.org/c3ref/open.html) for a /// description of valid flag combinations. /// /// # Failure /// /// Will return `Err` if `vfs` cannot be converted to a C-compatible /// string or if the underlying SQLite open call fails. pub async fn open_in_memory_with_flags_and_vfs(flags: OpenFlags, vfs: &str) -> Result { let vfs = vfs.to_owned(); start(move || rusqlite::Connection::open_in_memory_with_flags_and_vfs(flags, &vfs)) .await .map_err(Error::Rusqlite) } /// Call a function in background thread and get the result /// asynchronously. /// /// # Failure /// /// Will return `Err` if the database connection has been closed. pub async fn call(&self, function: F) -> Result where F: FnOnce(&mut rusqlite::Connection) -> Result + 'static + Send, R: Send + 'static, { let (sender, receiver) = oneshot::channel::>(); self.sender .send(Message::Execute(Box::new(move |conn| { let value = function(conn); let _ = sender.send(value); }))) .map_err(|_| Error::ConnectionClosed)?; receiver.await.map_err(|_| Error::ConnectionClosed)? } /// Call a function in background thread and get the result /// asynchronously. /// /// This method can cause a `panic` if the underlying database connection is closed. /// it is a more user-friendly alternative to the [`Connection::call`] method. /// It should be safe if the connection is never explicitly closed (using the [`Connection::close`] call). /// /// Calling this on a closed connection will cause a `panic`. pub async fn call_unwrap(&self, function: F) -> R where F: FnOnce(&mut rusqlite::Connection) -> R + Send + 'static, R: Send + 'static, { let (sender, receiver) = oneshot::channel::(); self.sender .send(Message::Execute(Box::new(move |conn| { let value = function(conn); let _ = sender.send(value); }))) .expect("database connection should be open"); receiver.await.expect(BUG_TEXT) } /// Close the database connection. /// /// This is functionally equivalent to the `Drop` implementation for /// `Connection`. It consumes the `Connection`, but on error returns it /// to the caller for retry purposes. /// /// If successful, any following `close` operations performed /// on `Connection` copies will succeed immediately. /// /// On the other hand, any calls to [`Connection::call`] will return a [`Error::ConnectionClosed`], /// and any calls to [`Connection::call_unwrap`] will cause a `panic`. /// /// # Failure /// /// Will return `Err` if the underlying SQLite close call fails. pub async fn close(self) -> Result<()> { let (sender, receiver) = oneshot::channel::>(); if let Err(crossbeam_channel::SendError(_)) = self.sender.send(Message::Close(sender)) { // If the channel is closed on the other side, it means the connection closed successfully // This is a safeguard against calling close on a `Copy` of the connection return Ok(()); } let result = receiver.await; if result.is_err() { // If we get a RecvError at this point, it also means the channel closed in the meantime // we can assume the connection is closed return Ok(()); } result.unwrap().map_err(|e| Error::Close((self, e))) } } impl Debug for Connection { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Connection").finish() } } impl From for Connection { fn from(conn: rusqlite::Connection) -> Self { let (sender, receiver) = crossbeam_channel::unbounded::(); thread::spawn(move || event_loop(conn, receiver)); Self { sender } } } async fn start(open: F) -> rusqlite::Result where F: FnOnce() -> rusqlite::Result + Send + 'static, { let (sender, receiver) = crossbeam_channel::unbounded::(); let (result_sender, result_receiver) = oneshot::channel(); thread::spawn(move || { let conn = match open() { Ok(c) => c, Err(e) => { let _ = result_sender.send(Err(e)); return; } }; if let Err(_e) = result_sender.send(Ok(())) { return; } event_loop(conn, receiver); }); result_receiver .await .expect(BUG_TEXT) .map(|_| Connection { sender }) } fn event_loop(mut conn: rusqlite::Connection, receiver: Receiver) { while let Ok(message) = receiver.recv() { match message { Message::Execute(f) => f(&mut conn), Message::Close(s) => { let result = conn.close(); match result { Ok(v) => { s.send(Ok(v)).expect(BUG_TEXT); break; } Err((c, e)) => { conn = c; s.send(Err(e)).expect(BUG_TEXT); } } } } } } tokio-rusqlite-0.6.0/src/tests.rs000064400000000000000000000146631046102023000151330ustar 00000000000000use std::fmt::Display; use crate::*; #[tokio::test] async fn open_in_memory_test() -> Result<()> { let conn = Connection::open_in_memory().await; assert!(conn.is_ok()); Ok(()) } #[tokio::test] async fn call_success_test() -> Result<()> { let conn = Connection::open_in_memory().await?; let result = conn .call(|conn| { conn.execute( "CREATE TABLE person(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL);", [], ) .map_err(|e| e.into()) }) .await; assert_eq!(0, result.unwrap()); Ok(()) } #[tokio::test] async fn call_unwrap_success_test() -> Result<()> { let conn = Connection::open_in_memory().await?; let result = conn .call_unwrap(|conn| { conn.execute( "CREATE TABLE person(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL);", [], ) .unwrap() }) .await; assert_eq!(0, result); Ok(()) } #[tokio::test] async fn call_failure_test() -> Result<()> { let conn = Connection::open_in_memory().await?; let result = conn .call(|conn| conn.execute("Invalid sql", []).map_err(|e| e.into())) .await; assert!(match result.unwrap_err() { crate::Error::Rusqlite(e) => { e == rusqlite::Error::SqlInputError { error: ffi::Error { code: ErrorCode::Unknown, extended_code: 1, }, msg: "near \"Invalid\": syntax error".to_string(), sql: "Invalid sql".to_string(), offset: 0, } } _ => false, }); Ok(()) } #[tokio::test] async fn close_success_test() -> Result<()> { let conn = Connection::open_in_memory().await?; assert!(conn.close().await.is_ok()); Ok(()) } #[tokio::test] async fn double_close_test() -> Result<()> { let conn = Connection::open_in_memory().await?; let conn2 = conn.clone(); assert!(conn.close().await.is_ok()); assert!(conn2.close().await.is_ok()); Ok(()) } #[tokio::test] async fn close_call_test() -> Result<()> { let conn = Connection::open_in_memory().await?; let conn2 = conn.clone(); assert!(conn.close().await.is_ok()); let result = conn2 .call(|conn| conn.execute("SELECT 1;", []).map_err(|e| e.into())) .await; assert!(matches!( result.unwrap_err(), crate::Error::ConnectionClosed )); Ok(()) } #[tokio::test] #[should_panic] async fn close_call_unwrap_test() { let conn = Connection::open_in_memory().await.unwrap(); let conn2 = conn.clone(); assert!(conn.close().await.is_ok()); conn2 .call_unwrap(|conn| conn.execute("SELECT 1;", [])) .await .unwrap(); } #[tokio::test] async fn close_failure_test() -> Result<()> { let conn = Connection::open_in_memory().await?; conn.call(|conn| { conn.execute( "CREATE TABLE person(id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL);", [], ) .map_err(|e| e.into()) }) .await?; conn.call(|conn| { // Leak a prepared statement to make the database uncloseable // See https://www.sqlite.org/c3ref/close.html for details regarding this behaviour let stmt = Box::new(conn.prepare("INSERT INTO person VALUES (1, ?1);").unwrap()); Box::leak(stmt); Ok(()) }) .await?; assert!(match conn.close().await.unwrap_err() { crate::Error::Close((_, e)) => { e == rusqlite::Error::SqliteFailure( ffi::Error { code: ErrorCode::DatabaseBusy, extended_code: 5, }, Some( "unable to close due to unfinalized statements or unfinished backups" .to_string(), ), ) } _ => false, }); Ok(()) } #[tokio::test] async fn debug_format_test() -> Result<()> { let conn = Connection::open_in_memory().await?; assert_eq!("Connection".to_string(), format!("{conn:?}")); Ok(()) } #[tokio::test] async fn test_error_display() -> Result<()> { let conn = Connection::open_in_memory().await?; let error = crate::Error::Close((conn, rusqlite::Error::InvalidQuery)); assert_eq!( "Close((Connection, \"Query is not read-only\"))", format!("{error}") ); let error = crate::Error::ConnectionClosed; assert_eq!("ConnectionClosed", format!("{error}")); let error = crate::Error::Rusqlite(rusqlite::Error::InvalidQuery); assert_eq!("Rusqlite(\"Query is not read-only\")", format!("{error}")); Ok(()) } #[tokio::test] async fn test_error_source() -> Result<()> { let conn = Connection::open_in_memory().await?; let error = crate::Error::Close((conn, rusqlite::Error::InvalidQuery)); assert_eq!( std::error::Error::source(&error) .and_then(|e| e.downcast_ref::()) .unwrap(), &rusqlite::Error::InvalidQuery, ); let error = crate::Error::ConnectionClosed; assert_eq!( std::error::Error::source(&error).and_then(|e| e.downcast_ref::()), None, ); let error = crate::Error::Rusqlite(rusqlite::Error::InvalidQuery); assert_eq!( std::error::Error::source(&error) .and_then(|e| e.downcast_ref::()) .unwrap(), &rusqlite::Error::InvalidQuery, ); Ok(()) } fn failable_func(_: &rusqlite::Connection) -> std::result::Result<(), MyError> { Err(MyError::MySpecificError) } #[tokio::test] async fn test_ergonomic_errors() -> Result<()> { let conn = Connection::open_in_memory().await?; let res = conn .call(|conn| failable_func(conn).map_err(|e| Error::Other(Box::new(e)))) .await .unwrap_err(); let err = std::error::Error::source(&res) .and_then(|e| e.downcast_ref::()) .unwrap(); assert!(matches!(err, MyError::MySpecificError)); Ok(()) } // The rest is boilerplate, not really that important #[derive(Debug)] enum MyError { MySpecificError, } impl Display for MyError { fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { Ok(()) } } impl std::error::Error for MyError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { None } }