8b5277462d
Fixes the following cargo-audit feedback: ``` Crate: openssl Version: 0.10.64 Title: `MemBio::get_buf` has undefined behavior with empty buffers Date: 2024-07-21 ID: RUSTSEC-2024-0357 URL: https://rustsec.org/advisories/RUSTSEC-2024-0357 Solution: Upgrade to >=0.10.66 Dependency tree: openssl 0.10.64 ├── sqlx-cli 0.8.3 └── native-tls 0.2.11 └── sqlx-core 0.8.3 ├── sqlx-sqlite 0.8.3 │ ├── sqlx-macros-core 0.8.3 │ │ └── sqlx-macros 0.8.3 │ │ └── sqlx 0.8.3 │ │ ├── sqlx-test 0.1.0 │ │ │ └── sqlx 0.8.3 │ │ ├── sqlx-sqlite 0.8.3 │ │ ├── sqlx-postgres 0.8.3 │ │ │ ├── sqlx-macros-core 0.8.3 │ │ │ └── sqlx 0.8.3 │ │ ├── sqlx-mysql 0.8.3 │ │ │ ├── sqlx-macros-core 0.8.3 │ │ │ └── sqlx 0.8.3 │ │ ├── sqlx-example-sqlite-todos 0.1.0 │ │ ├── sqlx-example-postgres-transaction 0.1.0 │ │ ├── sqlx-example-postgres-todos 0.1.0 │ │ ├── sqlx-example-postgres-mockable-todos 0.1.0 │ │ ├── sqlx-example-postgres-listen 0.1.0 │ │ ├── sqlx-example-postgres-json 0.1.0 │ │ ├── sqlx-example-postgres-files 0.1.0 │ │ ├── sqlx-example-postgres-chat 0.1.0 │ │ ├── sqlx-example-postgres-axum-social 0.1.0 │ │ ├── sqlx-example-mysql-todos 0.1.0 │ │ ├── sqlx-core 0.8.3 │ │ └── sqlx-cli 0.8.3 │ └── sqlx 0.8.3 ├── sqlx-postgres 0.8.3 ├── sqlx-mysql 0.8.3 ├── sqlx-macros-core 0.8.3 ├── sqlx-macros 0.8.3 └── sqlx 0.8.3 Crate: futures-util Version: 0.3.30 Warning: yanked Dependency tree: futures-util 0.3.30 ├── tower-http 0.3.5 │ └── axum 0.5.17 │ └── sqlx-example-postgres-axum-social 0.1.0 ├── tower 0.4.13 │ ├── tower-http 0.3.5 │ ├── sqlx-example-postgres-axum-social 0.1.0 │ └── axum 0.5.17 ├── sqlx-sqlite 0.8.3 │ ├── sqlx-macros-core 0.8.3 │ │ └── sqlx-macros 0.8.3 │ │ └── sqlx 0.8.3 │ │ ├── sqlx-test 0.1.0 │ │ │ └── sqlx 0.8.3 │ │ ├── sqlx-sqlite 0.8.3 │ │ ├── sqlx-postgres 0.8.3 │ │ │ ├── sqlx-macros-core 0.8.3 │ │ │ └── sqlx 0.8.3 │ │ ├── sqlx-mysql 0.8.3 │ │ │ ├── sqlx-macros-core 0.8.3 │ │ │ └── sqlx 0.8.3 │ │ ├── sqlx-example-sqlite-todos 0.1.0 │ │ ├── sqlx-example-postgres-transaction 0.1.0 │ │ ├── sqlx-example-postgres-todos 0.1.0 │ │ ├── sqlx-example-postgres-mockable-todos 0.1.0 │ │ ├── sqlx-example-postgres-listen 0.1.0 │ │ ├── sqlx-example-postgres-json 0.1.0 │ │ ├── sqlx-example-postgres-files 0.1.0 │ │ ├── sqlx-example-postgres-chat 0.1.0 │ │ ├── sqlx-example-postgres-axum-social 0.1.0 │ │ ├── sqlx-example-mysql-todos 0.1.0 │ │ ├── sqlx-core 0.8.3 │ │ │ ├── sqlx-sqlite 0.8.3 │ │ │ ├── sqlx-postgres 0.8.3 │ │ │ ├── sqlx-mysql 0.8.3 │ │ │ ├── sqlx-macros-core 0.8.3 │ │ │ ├── sqlx-macros 0.8.3 │ │ │ └── sqlx 0.8.3 │ │ └── sqlx-cli 0.8.3 │ └── sqlx 0.8.3 ├── sqlx-postgres 0.8.3 ├── sqlx-mysql 0.8.3 ├── sqlx-core 0.8.3 ├── hyper 0.14.28 │ └── axum 0.5.17 ├── futures-executor 0.3.30 │ ├── sqlx-sqlite 0.8.3 │ └── futures 0.3.30 │ ├── sqlx-example-sqlite-todos 0.1.0 │ ├── sqlx-example-postgres-transaction 0.1.0 │ ├── sqlx-example-postgres-todos 0.1.0 │ ├── sqlx-example-postgres-mockable-todos 0.1.0 │ ├── sqlx-example-postgres-listen 0.1.0 │ ├── sqlx-example-postgres-json 0.1.0 │ ├── sqlx-example-postgres-chat 0.1.0 │ ├── sqlx-example-mysql-todos 0.1.0 │ ├── sqlx-cli 0.8.3 │ ├── sqlx 0.8.3 │ └── criterion 0.5.1 │ └── sqlx 0.8.3 ├── futures 0.3.30 ├── axum-core 0.2.9 │ └── axum 0.5.17 └── axum 0.5.17 Crate: url Version: 2.5.3 Warning: yanked Dependency tree: url 2.5.3 ├── validator 0.16.1 │ └── sqlx-example-postgres-axum-social 0.1.0 ├── sqlx-sqlite 0.8.3 │ ├── sqlx-macros-core 0.8.3 │ │ └── sqlx-macros 0.8.3 │ │ └── sqlx 0.8.3 │ │ ├── sqlx-test 0.1.0 │ │ │ └── sqlx 0.8.3 │ │ ├── sqlx-sqlite 0.8.3 │ │ ├── sqlx-postgres 0.8.3 │ │ │ ├── sqlx-macros-core 0.8.3 │ │ │ └── sqlx 0.8.3 │ │ ├── sqlx-mysql 0.8.3 │ │ │ ├── sqlx-macros-core 0.8.3 │ │ │ └── sqlx 0.8.3 │ │ ├── sqlx-example-sqlite-todos 0.1.0 │ │ ├── sqlx-example-postgres-transaction 0.1.0 │ │ ├── sqlx-example-postgres-todos 0.1.0 │ │ ├── sqlx-example-postgres-mockable-todos 0.1.0 │ │ ├── sqlx-example-postgres-listen 0.1.0 │ │ ├── sqlx-example-postgres-json 0.1.0 │ │ ├── sqlx-example-postgres-files 0.1.0 │ │ ├── sqlx-example-postgres-chat 0.1.0 │ │ ├── sqlx-example-postgres-axum-social 0.1.0 │ │ ├── sqlx-example-mysql-todos 0.1.0 │ │ ├── sqlx-core 0.8.3 │ │ │ ├── sqlx-sqlite 0.8.3 │ │ │ ├── sqlx-postgres 0.8.3 │ │ │ ├── sqlx-mysql 0.8.3 │ │ │ ├── sqlx-macros-core 0.8.3 │ │ │ ├── sqlx-macros 0.8.3 │ │ │ └── sqlx 0.8.3 │ │ └── sqlx-cli 0.8.3 │ └── sqlx 0.8.3 ├── sqlx-macros-core 0.8.3 ├── sqlx-core 0.8.3 └── sqlx 0.8.3 ``` Result of cargo update: ``` Updating crates.io index Updating addr2line v0.21.0 -> v0.24.2 Removing adler v1.0.2 Adding adler2 v2.0.0 Removing ahash v0.8.11 Updating aho-corasick v1.1.2 -> v1.1.3 Updating allocator-api2 v0.2.16 -> v0.2.21 Updating anstream v0.6.13 -> v0.6.18 Updating anstyle v1.0.6 -> v1.0.10 Updating anstyle-parse v0.2.3 -> v0.2.6 Updating anstyle-query v1.0.2 -> v1.1.2 Updating anstyle-wincon v3.0.2 -> v3.0.6 Updating anyhow v1.0.81 -> v1.0.95 Updating arrayvec v0.7.4 -> v0.7.6 Updating assert_cmd v2.0.14 -> v2.0.16 Updating async-channel v2.2.0 -> v2.3.1 Updating async-executor v1.8.0 -> v1.13.1 Updating async-io v2.3.2 -> v2.4.0 Updating async-lock v3.3.0 -> v3.4.0 Updating async-task v4.7.0 -> v4.7.1 Updating async-trait v0.1.77 -> v0.1.85 Updating autocfg v1.1.0 -> v1.4.0 Updating aws-lc-rs v1.8.0 -> v1.12.0 Updating aws-lc-sys v0.19.0 -> v0.24.1 Updating backtrace v0.3.69 -> v0.3.74 Updating base64 v0.22.0 -> v0.22.1 Removing basic-toml v0.1.9 Updating bigdecimal v0.4.3 -> v0.4.7 Updating bindgen v0.69.4 -> v0.69.5 (latest: v0.71.1) Updating bitflags v2.4.2 -> v2.7.0 Updating blocking v1.5.1 -> v1.6.1 Updating borsh v1.5.1 -> v1.5.3 Updating borsh-derive v1.5.1 -> v1.5.3 Updating bstr v1.9.1 -> v1.11.3 Updating bumpalo v3.15.4 -> v3.16.0 Updating bytes v1.5.0 -> v1.9.0 Updating camino v1.1.6 -> v1.1.9 Updating cargo-platform v0.1.7 -> v0.1.9 Updating cc v1.1.6 -> v1.2.8 Adding cfg_aliases v0.1.1 (latest: v0.2.1) Updating chrono v0.4.35 -> v0.4.39 Updating clap v4.5.2 -> v4.5.26 Updating clap_builder v4.5.2 -> v4.5.26 Updating clap_complete v4.5.1 -> v4.5.42 Updating clap_derive v4.5.0 -> v4.5.24 Updating clap_lex v0.7.0 -> v0.7.4 Updating cmake v0.1.50 -> v0.1.52 Updating colorchoice v1.0.0 -> v1.0.3 Updating concurrent-queue v2.4.0 -> v2.5.0 Updating console v0.15.8 -> v0.15.10 Adding core-foundation v0.10.0 Updating core-foundation-sys v0.8.6 -> v0.8.7 Updating cpufeatures v0.2.12 -> v0.2.16 Updating crc v3.0.1 -> v3.2.1 Updating crossbeam-deque v0.8.5 -> v0.8.6 Updating crossbeam-queue v0.3.11 -> v0.3.12 Updating crossbeam-utils v0.8.19 -> v0.8.21 Updating darling v0.20.8 -> v0.20.10 Updating darling_core v0.20.8 -> v0.20.10 Updating darling_macro v0.20.8 -> v0.20.10 Updating der v0.7.8 -> v0.7.9 Updating dunce v1.0.4 -> v1.0.5 Updating either v1.10.0 -> v1.13.0 Updating encode_unicode v0.3.6 -> v1.0.0 Updating env_filter v0.1.0 -> v0.1.3 Updating env_logger v0.11.3 -> v0.11.6 Adding erased-serde v0.4.5 Updating errno v0.3.8 -> v0.3.10 Removing event-listener v4.0.3 Removing event-listener v5.2.0 Adding event-listener v5.4.0 Removing event-listener-strategy v0.4.0 Removing event-listener-strategy v0.5.0 Adding event-listener-strategy v0.5.3 Updating fastrand v2.0.1 -> v2.3.0 Updating filetime v0.2.23 -> v0.2.25 Removing finl_unicode v1.2.0 Updating flume v0.11.0 -> v0.11.1 Updating foldhash v0.1.3 -> v0.1.4 Updating futures v0.3.30 -> v0.3.31 Updating futures-channel v0.3.30 -> v0.3.31 Updating futures-core v0.3.30 -> v0.3.31 Updating futures-executor v0.3.30 -> v0.3.31 Updating futures-io v0.3.30 -> v0.3.31 Updating futures-lite v2.2.0 -> v2.5.0 Updating futures-macro v0.3.30 -> v0.3.31 Updating futures-sink v0.3.30 -> v0.3.31 Updating futures-task v0.3.30 -> v0.3.31 Updating futures-util v0.3.30 -> v0.3.31 Updating getrandom v0.2.12 -> v0.2.15 Updating gimli v0.28.1 -> v0.31.1 Updating glob v0.3.1 -> v0.3.2 Updating half v2.4.0 -> v2.4.1 Removing hashbrown v0.14.5 Adding hermit-abi v0.4.0 Updating httparse v1.8.0 -> v1.9.5 Updating hyper v0.14.28 -> v0.14.32 (latest: v1.5.2) Updating iana-time-zone v0.1.60 -> v0.1.61 Updating indexmap v2.2.5 -> v2.7.0 Updating instant v0.1.12 -> v0.1.13 Updating is-terminal v0.4.12 -> v0.4.13 Adding is_terminal_polyfill v1.70.1 Updating itoa v1.0.10 -> v1.0.14 Updating jobserver v0.1.31 -> v0.1.32 Updating js-sys v0.3.69 -> v0.3.76 Updating lazy_static v1.4.0 -> v1.5.0 Updating libc v0.2.153 -> v0.2.169 Updating libloading v0.8.4 -> v0.8.6 Updating libm v0.2.8 -> v0.2.11 Updating libredox v0.0.1 -> v0.1.3 Updating linux-raw-sys v0.4.13 -> v0.4.15 (latest: v0.7.0) Updating litemap v0.7.3 -> v0.7.4 Updating lock_api v0.4.11 -> v0.4.12 Updating log v0.4.21 -> v0.4.24 Updating lru v0.12.3 -> v0.12.5 Updating mac_address v1.1.5 -> v1.1.7 Updating memchr v2.7.1 -> v2.7.4 Adding memoffset v0.9.1 Updating miniz_oxide v0.7.2 -> v0.8.2 Adding mio v1.0.3 Removing mirai-annotations v1.12.0 Updating native-tls v0.2.11 -> v0.2.12 Adding nix v0.28.0 (latest: v0.29.0) Updating num-bigint v0.4.4 -> v0.4.6 Updating num-iter v0.1.44 -> v0.1.45 Updating num-traits v0.2.18 -> v0.2.19 Removing num_cpus v1.16.0 Updating object v0.32.2 -> v0.36.7 Updating once_cell v1.19.0 -> v1.20.2 Updating oorandom v11.1.3 -> v11.1.4 Updating openssl v0.10.64 -> v0.10.68 Updating openssl-src v300.2.3+3.2.1 -> v300.4.1+3.4.0 Updating openssl-sys v0.9.101 -> v0.9.104 Updating parking v2.2.0 -> v2.2.1 Updating parking_lot v0.12.1 -> v0.12.3 Updating parking_lot_core v0.9.9 -> v0.9.10 Updating paste v1.0.14 -> v1.0.15 Updating pin-project v1.1.5 -> v1.1.8 Updating pin-project-internal v1.1.5 -> v1.1.8 Updating pin-project-lite v0.2.13 -> v0.2.16 Updating piper v0.2.1 -> v0.2.4 Updating pkg-config v0.3.30 -> v0.3.31 Updating plotters v0.3.5 -> v0.3.7 Updating plotters-backend v0.3.5 -> v0.3.7 Updating plotters-svg v0.3.5 -> v0.3.7 Updating polling v3.5.0 -> v3.7.4 Updating ppv-lite86 v0.2.17 -> v0.2.20 Updating predicates v3.1.0 -> v3.1.3 Updating predicates-core v1.0.6 -> v1.0.9 Updating predicates-tree v1.0.9 -> v1.0.12 Updating prettyplease v0.2.17 -> v0.2.27 Updating proc-macro-crate v3.1.0 -> v3.2.0 Updating proc-macro2 v1.0.89 -> v1.0.93 Updating quote v1.0.35 -> v1.0.38 Updating rayon v1.9.0 -> v1.10.0 Updating redox_syscall v0.4.1 -> v0.5.8 Updating redox_users v0.4.4 -> v0.4.6 (latest: v0.5.0) Updating regex v1.10.3 -> v1.11.1 Updating regex-automata v0.4.6 -> v0.4.9 Updating regex-syntax v0.8.2 -> v0.8.5 Updating rkyv v0.7.44 -> v0.7.45 (latest: v0.8.9) Updating rkyv_derive v0.7.44 -> v0.7.45 (latest: v0.8.9) Updating rsa v0.9.6 -> v0.9.7 Updating rust_decimal v1.34.3 -> v1.36.0 Updating rustc-demangle v0.1.23 -> v0.1.24 Removing rustix v0.37.27 Removing rustix v0.38.31 Adding rustix v0.37.28 (latest: v0.38.43) Adding rustix v0.38.43 Updating rustls v0.23.11 -> v0.23.21 Updating rustls-native-certs v0.8.0 -> v0.8.1 Updating rustls-pemfile v2.1.2 -> v2.2.0 Updating rustls-pki-types v1.7.0 -> v1.10.1 Updating rustls-webpki v0.102.5 -> v0.102.8 Updating rustversion v1.0.17 -> v1.0.19 Updating ryu v1.0.17 -> v1.0.18 Updating schannel v0.1.23 -> v0.1.27 Removing security-framework v2.9.2 Adding security-framework v2.11.1 (latest: v3.2.0) Adding security-framework v3.2.0 Updating security-framework-sys v2.9.1 -> v2.14.0 Updating semver v1.0.22 -> v1.0.24 Updating serde v1.0.197 -> v1.0.217 Updating serde_derive v1.0.197 -> v1.0.217 Adding serde_fmt v1.0.3 Updating serde_json v1.0.114 -> v1.0.135 Adding serde_spanned v0.6.8 Updating signal-hook-mio v0.2.3 -> v0.2.4 Updating signal-hook-registry v1.4.1 -> v1.4.2 Updating simdutf8 v0.1.4 -> v0.1.5 Updating smallvec v1.13.1 -> v1.13.2 Updating socket2 v0.5.6 -> v0.5.8 Removing spin v0.5.2 Updating stringprep v0.1.4 -> v0.1.5 Removing strsim v0.10.0 Removing strsim v0.11.0 Adding strsim v0.11.1 Updating subtle v2.5.0 -> v2.6.1 Adding sval v2.13.2 Adding sval_buffer v2.13.2 Adding sval_dynamic v2.13.2 Adding sval_fmt v2.13.2 Adding sval_json v2.13.2 Adding sval_nested v2.13.2 Adding sval_ref v2.13.2 Adding sval_serde v2.13.2 Updating syn v2.0.87 -> v2.0.96 Removing syn_derive v0.1.8 Adding target-triple v0.1.3 Updating tempfile v3.10.1 -> v3.15.0 Updating termtree v0.4.1 -> v0.5.1 Removing thiserror v1.0.58 Removing thiserror v2.0.0 Adding thiserror v1.0.69 (latest: v2.0.11) Adding thiserror v2.0.11 Removing thiserror-impl v1.0.58 Removing thiserror-impl v2.0.0 Adding thiserror-impl v1.0.69 (latest: v2.0.11) Adding thiserror-impl v2.0.11 Updating time v0.3.36 -> v0.3.37 Updating time-macros v0.2.18 -> v0.2.19 Updating tinyvec v1.6.0 -> v1.8.1 Updating tokio v1.36.0 -> v1.43.0 Updating tokio-macros v2.2.0 -> v2.5.0 Updating tokio-stream v0.1.14 -> v0.1.17 Adding toml v0.8.19 Updating toml_datetime v0.6.6 -> v0.6.8 Updating toml_edit v0.21.1 -> v0.22.22 Updating tower-layer v0.3.2 -> v0.3.3 Updating tower-service v0.3.2 -> v0.3.3 Updating tracing v0.1.40 -> v0.1.41 Updating tracing-attributes v0.1.27 -> v0.1.28 Updating tracing-core v0.1.32 -> v0.1.33 Updating trybuild v1.0.89 -> v1.0.101 Adding typeid v1.0.2 Updating unicode-bidi v0.3.15 -> v0.3.18 Updating unicode-ident v1.0.12 -> v1.0.14 Updating unicode-normalization v0.1.23 -> v0.1.24 Adding unicode-properties v0.1.3 Updating unicode-segmentation v1.11.0 -> v1.12.0 Removing unicode-width v0.1.13 Adding unicode-width v0.1.14 (latest: v0.2.0) Adding unicode-width v0.2.0 Updating url v2.5.3 -> v2.5.4 Updating utf8parse v0.2.1 -> v0.2.2 Updating uuid v1.7.0 -> v1.11.1 Updating value-bag v1.8.0 -> v1.10.0 Adding value-bag-serde1 v1.10.0 Adding value-bag-sval2 v1.10.0 Updating version_check v0.9.4 -> v0.9.5 Updating waker-fn v1.1.1 -> v1.2.0 Updating wasm-bindgen v0.2.92 -> v0.2.99 Updating wasm-bindgen-backend v0.2.92 -> v0.2.99 Updating wasm-bindgen-futures v0.4.42 -> v0.4.49 Updating wasm-bindgen-macro v0.2.92 -> v0.2.99 Updating wasm-bindgen-macro-support v0.2.92 -> v0.2.99 Updating wasm-bindgen-shared v0.2.92 -> v0.2.99 Updating web-sys v0.3.69 -> v0.3.76 Updating webpki-roots v0.26.3 -> v0.26.7 Updating whoami v1.5.1 -> v1.5.2 Updating winapi-util v0.1.6 -> v0.1.9 Adding windows-sys v0.59.0 Updating windows-targets v0.52.4 -> v0.52.6 (latest: v0.53.0) Updating windows_aarch64_gnullvm v0.52.4 -> v0.52.6 (latest: v0.53.0) Updating windows_aarch64_msvc v0.52.4 -> v0.52.6 (latest: v0.53.0) Updating windows_i686_gnu v0.52.4 -> v0.52.6 (latest: v0.53.0) Adding windows_i686_gnullvm v0.52.6 (latest: v0.53.0) Updating windows_i686_msvc v0.52.4 -> v0.52.6 (latest: v0.53.0) Updating windows_x86_64_gnu v0.52.4 -> v0.52.6 (latest: v0.53.0) Updating windows_x86_64_gnullvm v0.52.4 -> v0.52.6 (latest: v0.53.0) Updating windows_x86_64_msvc v0.52.4 -> v0.52.6 (latest: v0.53.0) Updating winnow v0.5.40 -> v0.6.24 Updating yoke v0.7.4 -> v0.7.5 Updating yoke-derive v0.7.4 -> v0.7.5 Updating zerocopy v0.7.32 -> v0.7.35 (latest: v0.8.14) Updating zerocopy-derive v0.7.32 -> v0.7.35 (latest: v0.8.14) Updating zerofrom v0.1.4 -> v0.1.5 Updating zerofrom-derive v0.1.4 -> v0.1.5 Updating zeroize v1.7.0 -> v1.8.1 Removing zeroize_derive v1.4.2 note: pass `--verbose` to see 88 unchanged dependencies behind latest ``` |
||
---|---|---|
.github | ||
benches/sqlite | ||
contrib/ide/vscode | ||
examples | ||
sqlx-bench | ||
sqlx-cli | ||
sqlx-core | ||
sqlx-macros | ||
sqlx-macros-core | ||
sqlx-mysql | ||
sqlx-postgres | ||
sqlx-sqlite | ||
sqlx-test | ||
src | ||
tests | ||
.editorconfig | ||
.gitattributes | ||
.gitignore | ||
Cargo.lock | ||
Cargo.toml | ||
CHANGELOG.md | ||
clippy.toml | ||
CONTRIBUTING.md | ||
FAQ.md | ||
gen-changelog.sh | ||
LICENSE-APACHE | ||
LICENSE-MIT | ||
README.md | ||
rust-toolchain.toml |
SQLx
Have a question? Be sure to check the FAQ first!
SQLx is an async, pure Rust† SQL crate featuring compile-time checked queries without a DSL.
-
Truly Asynchronous. Built from the ground-up using async/await for maximum concurrency.
-
Compile-time checked queries (if you want). See SQLx is not an ORM.
-
Database Agnostic. Support for PostgreSQL, MySQL, MariaDB, SQLite.
- MSSQL was supported prior to version 0.7, but has been removed pending a full rewrite of the driver as part of our SQLx Pro initiative.
-
Pure Rust. The Postgres and MySQL/MariaDB drivers are written in pure Rust using zero unsafe†† code.
-
Runtime Agnostic. Works on different runtimes (
async-std
/tokio
/actix
) and TLS backends (native-tls
,rustls
).
† The SQLite driver uses the libsqlite3 C library as SQLite is an embedded database (the only way we could be pure Rust for SQLite is by porting all of SQLite to Rust).
†† SQLx uses #![forbid(unsafe_code)]
unless the sqlite
feature is enabled.
The SQLite driver directly invokes the SQLite3 API via libsqlite3-sys
, which requires unsafe
.
-
Cross-platform. Being native Rust, SQLx will compile anywhere Rust is supported.
-
Built-in connection pooling with
sqlx::Pool
. -
Row streaming. Data is read asynchronously from the database and decoded on demand.
-
Automatic statement preparation and caching. When using the high-level query API (
sqlx::query
), statements are prepared and cached per connection. -
Simple (unprepared) query execution including fetching results into the same
Row
types used by the high-level API. Supports batch execution and returns results from all statements. -
Transport Layer Security (TLS) where supported (MySQL, MariaDB and PostgreSQL).
-
Asynchronous notifications using
LISTEN
andNOTIFY
for PostgreSQL. -
Nested transactions with support for save points.
-
Any
database driver for changing the database driver at runtime. AnAnyPool
connects to the driver indicated by the URL scheme.
Install
SQLx is compatible with the async-std
, tokio
, and actix
runtimes; and, the native-tls
and rustls
TLS backends. When adding the dependency, you must choose a runtime feature that is runtime
+ tls
.
# Cargo.toml
[dependencies]
# PICK ONE OF THE FOLLOWING:
# tokio (no TLS)
sqlx = { version = "0.8", features = [ "runtime-tokio" ] }
# tokio + native-tls
sqlx = { version = "0.8", features = [ "runtime-tokio", "tls-native-tls" ] }
# tokio + rustls with ring and WebPKI CA certificates
sqlx = { version = "0.8", features = [ "runtime-tokio", "tls-rustls-ring-webpki" ] }
# tokio + rustls with ring and platform's native CA certificates
sqlx = { version = "0.8", features = [ "runtime-tokio", "tls-rustls-ring-native-roots" ] }
# tokio + rustls with aws-lc-rs
sqlx = { version = "0.8", features = [ "runtime-tokio", "tls-rustls-aws-lc-rs" ] }
# async-std (no TLS)
sqlx = { version = "0.8", features = [ "runtime-async-std" ] }
# async-std + native-tls
sqlx = { version = "0.8", features = [ "runtime-async-std", "tls-native-tls" ] }
# async-std + rustls with ring and WebPKI CA certificates
sqlx = { version = "0.8", features = [ "runtime-async-std", "tls-rustls-ring-webpki" ] }
# async-std + rustls with ring and platform's native CA certificates
sqlx = { version = "0.8", features = [ "runtime-async-std", "tls-rustls-ring-native-roots" ] }
# async-std + rustls with aws-lc-rs
sqlx = { version = "0.8", features = [ "runtime-async-std", "tls-rustls-aws-lc-rs" ] }
Cargo Feature Flags
For backward-compatibility reasons, the runtime and TLS features can either be chosen together as a single feature, or separately.
For forward compatibility, you should use the separate runtime and TLS features as the combination features may be removed in the future.
-
runtime-async-std
: Use theasync-std
runtime without enabling a TLS backend. -
runtime-async-std-native-tls
: Use theasync-std
runtime andnative-tls
TLS backend (SOFT-DEPRECATED). -
runtime-async-std-rustls
: Use theasync-std
runtime andrustls
TLS backend (SOFT-DEPRECATED). -
runtime-tokio
: Use thetokio
runtime without enabling a TLS backend. -
runtime-tokio-native-tls
: Use thetokio
runtime andnative-tls
TLS backend (SOFT-DEPRECATED). -
runtime-tokio-rustls
: Use thetokio
runtime andrustls
TLS backend (SOFT-DEPRECATED).- Actix-web is fully compatible with Tokio and so a separate runtime feature is no longer needed.
-
tls-native-tls
: Use thenative-tls
TLS backend (OpenSSL on *nix, SChannel on Windows, Secure Transport on macOS). -
tls-rustls
: Use therustls
TLS backend (cross-platform backend, only supports TLS 1.2 and 1.3). -
postgres
: Add support for the Postgres database server. -
mysql
: Add support for the MySQL/MariaDB database server. -
mssql
: Add support for the MSSQL database server. -
sqlite
: Add support for the self-contained SQLite database engine with SQLite bundled and statically-linked. -
sqlite-unbundled
: The same as above (sqlite
), but link SQLite from the system instead of the bundled version.- Allows updating SQLite independently of SQLx or using forked versions.
- You must have SQLite installed on the system or provide a path to the library at build time.
See the
rusqlite
README for details. - May result in link errors if the SQLite version is too old. Version
3.20.0
or newer is recommended. - Can increase build time due to the use of bindgen.
-
any
: Add support for theAny
database driver, which can proxy to a database driver at runtime. -
derive
: Add support for the derive family macros, those areFromRow
,Type
,Encode
,Decode
. -
macros
: Add support for thequery*!
macros, which allows compile-time checked queries. -
migrate
: Add support for the migration management andmigrate!
macro, which allow compile-time embedded migrations. -
uuid
: Add support for UUID (in Postgres). -
chrono
: Add support for date and time types fromchrono
. -
time
: Add support for date and time types fromtime
crate (alternative tochrono
, which is preferred byquery!
macro, if both enabled) -
bstr
: Add support forbstr::BString
. -
bigdecimal
: Add support forNUMERIC
using thebigdecimal
crate. -
rust_decimal
: Add support forNUMERIC
using therust_decimal
crate. -
ipnetwork
: Add support forINET
andCIDR
(in postgres) using theipnetwork
crate. -
json
: Add support forJSON
andJSONB
(in postgres) using theserde_json
crate. -
Offline mode is now always enabled. See sqlx-cli/README.md.
SQLx is not an ORM!
SQLx supports compile-time checked queries. It does not, however, do this by providing a Rust API or DSL (domain-specific language) for building queries. Instead, it provides macros that take regular SQL as input and ensure that it is valid for your database. The way this works is that SQLx connects to your development DB at compile time to have the database itself verify (and return some info on) your SQL queries. This has some potentially surprising implications:
- Since SQLx never has to parse the SQL string itself, any syntax that the development DB accepts can be used (including things added by database extensions)
- Due to the different amount of information databases let you retrieve about queries, the extent of SQL verification you get from the query macros depends on the database
If you are looking for an (asynchronous) ORM, you can check out our new Ecosystem wiki page!
Usage
See the examples/
folder for more in-depth usage.
Quickstart
use sqlx::postgres::PgPoolOptions;
// use sqlx::mysql::MySqlPoolOptions;
// etc.
#[async_std::main] // Requires the `attributes` feature of `async-std`
// or #[tokio::main]
// or #[actix_web::main]
async fn main() -> Result<(), sqlx::Error> {
// Create a connection pool
// for MySQL/MariaDB, use MySqlPoolOptions::new()
// for SQLite, use SqlitePoolOptions::new()
// etc.
let pool = PgPoolOptions::new()
.max_connections(5)
.connect("postgres://postgres:password@localhost/test").await?;
// Make a simple query to return the given parameter (use a question mark `?` instead of `$1` for MySQL/MariaDB)
let row: (i64,) = sqlx::query_as("SELECT $1")
.bind(150_i64)
.fetch_one(&pool).await?;
assert_eq!(row.0, 150);
Ok(())
}
Connecting
A single connection can be established using any of the database connection types and calling connect()
.
use sqlx::Connection;
let conn = SqliteConnection::connect("sqlite::memory:").await?;
Generally, you will want to instead create a connection pool (sqlx::Pool
) for the application to
regulate how many server-side connections it's using.
let pool = MySqlPool::connect("mysql://user:pass@host/database").await?;
Querying
In SQL, queries can be separated into prepared (parameterized) or unprepared (simple). Prepared queries have their
query plan cached, use a binary mode of communication (lower bandwidth and faster decoding), and utilize parameters
to avoid SQL injection. Unprepared queries are simple and intended only for use where a prepared statement
will not work, such as various database commands (e.g., PRAGMA
or SET
or BEGIN
).
SQLx supports all operations with both types of queries. In SQLx, a &str
is treated as an unprepared query,
and a Query
or QueryAs
struct is treated as a prepared query.
// low-level, Executor trait
conn.execute("BEGIN").await?; // unprepared, simple query
conn.execute(sqlx::query("DELETE FROM table")).await?; // prepared, cached query
We should prefer to use the high-level query
interface whenever possible. To make this easier, there are finalizers
on the type to avoid the need to wrap with an executor.
sqlx::query("DELETE FROM table").execute(&mut conn).await?;
sqlx::query("DELETE FROM table").execute(&pool).await?;
The execute
query finalizer returns the number of affected rows, if any, and drops all received results.
In addition, there are fetch
, fetch_one
, fetch_optional
, and fetch_all
to receive results.
The Query
type returned from sqlx::query
will return Row<'conn>
from the database. Column values can be accessed
by ordinal or by name with row.get()
. As the Row
retains an immutable borrow on the connection, only one
Row
may exist at a time.
The fetch
query finalizer returns a stream-like type that iterates through the rows in the result sets.
// provides `try_next`
use futures::TryStreamExt;
// provides `try_get`
use sqlx::Row;
let mut rows = sqlx::query("SELECT * FROM users WHERE email = ?")
.bind(email)
.fetch(&mut conn);
while let Some(row) = rows.try_next().await? {
// map the row into a user-defined domain type
let email: &str = row.try_get("email")?;
}
To assist with mapping the row into a domain type, one of two idioms may be used:
let mut stream = sqlx::query("SELECT * FROM users")
.map(|row: PgRow| {
// map the row into a user-defined domain type
})
.fetch(&mut conn);
#[derive(sqlx::FromRow)]
struct User { name: String, id: i64 }
let mut stream = sqlx::query_as::<_, User>("SELECT * FROM users WHERE email = ? OR name = ?")
.bind(user_email)
.bind(user_name)
.fetch(&mut conn);
Instead of a stream of results, we can use fetch_one
or fetch_optional
to request one required or optional result
from the database.
Compile-time verification
We can use the macro, sqlx::query!
to achieve compile-time syntactic and semantic verification of the SQL, with
an output to an anonymous record type where each SQL column is a Rust field (using raw identifiers where needed).
let countries = sqlx::query!(
"
SELECT country, COUNT(*) as count
FROM users
GROUP BY country
WHERE organization = ?
",
organization
)
.fetch_all(&pool) // -> Vec<{ country: String, count: i64 }>
.await?;
// countries[0].country
// countries[0].count
Differences from query()
:
-
The input (or bind) parameters must be given all at once (and they are compile-time validated to be the right number and the right type).
-
The output type is an anonymous record. In the above example the type would be similar to:
{ country: String, count: i64 }
-
The
DATABASE_URL
environment variable must be set at build time to a database which it can prepare queries against; the database does not have to contain any data but must be the same kind (MySQL, Postgres, etc.) and have the same schema as the database you will be connecting to at runtime.For convenience, you can use a
.env
file1 to set DATABASE_URL so that you don't have to pass it every time:DATABASE_URL=mysql://localhost/my_database
The biggest downside to query!()
is that the output type cannot be named (due to Rust not
officially supporting anonymous records). To address that, there is a query_as!()
macro that is
mostly identical except that you can name the output type.
// no traits are needed
struct Country { country: String, count: i64 }
let countries = sqlx::query_as!(Country,
"
SELECT country, COUNT(*) as count
FROM users
GROUP BY country
WHERE organization = ?
",
organization
)
.fetch_all(&pool) // -> Vec<Country>
.await?;
// countries[0].country
// countries[0].count
To avoid the need of having a development database around to compile the project even when no
modifications (to the database-accessing parts of the code) are done, you can enable "offline mode"
to cache the results of the SQL query analysis using the sqlx
command-line tool. See
sqlx-cli/README.md.
Compile-time verified queries do quite a bit of work at compile time. Incremental actions like
cargo check
and cargo build
can be significantly faster when using an optimized build by
putting the following in your Cargo.toml
(More information in the
Profiles section of The Cargo Book)
[profile.dev.package.sqlx-macros]
opt-level = 3
1 The dotenv
crate itself appears abandoned as of December 2021
so we now use the dotenvy
crate instead. The file format is the same.
Safety
This crate uses #![forbid(unsafe_code)]
to ensure everything is implemented in 100% Safe Rust.
If the sqlite
feature is enabled, this is downgraded to #![deny(unsafe_code)]
with #![allow(unsafe_code)]
on the
sqlx::sqlite
module. There are several places where we interact with the C SQLite API. We try to document each call for the invariants we're assuming. We absolutely welcome auditing of, and feedback on, our unsafe code usage.
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any Contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.