Skip to content

Release/0.7.0 alpha.2 #2408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 17, 2023
Merged
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
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ members = [
]

[workspace.package]
version = "0.7.0-alpha.1"
version = "0.7.0-alpha.2"
license = "MIT OR Apache-2.0"
edition = "2021"
repository = "https://github.com/launchbadge/sqlx"
Expand Down Expand Up @@ -114,17 +114,17 @@ regexp = ["sqlx-sqlite?/regexp"]

[workspace.dependencies]
# Core Crates
sqlx-core = { version = "=0.7.0-alpha.1", path = "sqlx-core" }
sqlx-macros-core = { version = "=0.7.0-alpha.1", path = "sqlx-macros-core" }
sqlx-macros = { version = "=0.7.0-alpha.1", path = "sqlx-macros" }
sqlx-core = { version = "=0.7.0-alpha.2", path = "sqlx-core" }
sqlx-macros-core = { version = "=0.7.0-alpha.2", path = "sqlx-macros-core" }
sqlx-macros = { version = "=0.7.0-alpha.2", path = "sqlx-macros" }

# Driver crates
sqlx-mysql = { version = "=0.7.0-alpha.1", path = "sqlx-mysql" }
sqlx-postgres = { version = "=0.7.0-alpha.1", path = "sqlx-postgres" }
sqlx-sqlite = { version = "=0.7.0-alpha.1", path = "sqlx-sqlite" }
sqlx-mysql = { version = "=0.7.0-alpha.2", path = "sqlx-mysql" }
sqlx-postgres = { version = "=0.7.0-alpha.2", path = "sqlx-postgres" }
sqlx-sqlite = { version = "=0.7.0-alpha.2", path = "sqlx-sqlite" }

# Facade crate (for reference from sqlx-cli)
sqlx = { version = "=0.7.0-alpha.1", path = "." }
sqlx = { version = "=0.7.0-alpha.2", path = "." }

# Common type integrations shared by multiple driver crates.
# These are optional unless enabled in a workspace crate.
Expand All @@ -150,8 +150,8 @@ features = ["time", "net", "sync", "fs", "io-util", "rt"]
default-features = false

[dependencies]
sqlx-core = { version = "=0.7.0-alpha.1", path = "sqlx-core", features = ["offline", "migrate"], default-features = false }
sqlx-macros = { version = "=0.7.0-alpha.1", path = "sqlx-macros", default-features = false, optional = true }
sqlx-core = { workspace = true, features = ["offline", "migrate"], default-features = false }
sqlx-macros = { workspace = true, default-features = false, optional = true }

sqlx-mysql = { workspace = true, optional = true }
sqlx-postgres = { workspace = true, optional = true }
Expand Down
53 changes: 16 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ with C, those interactions are `unsafe`.

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 chose a runtime feature that is `runtime` + `tls`.

NOTE: these examples are for the coming 0.7 release, which is currently in an alpha cycle.
For the last stable release, 0.6.2, see [the previous verison of this document](https://github.com/launchbadge/sqlx/blob/v0.6.2/README.md).

[`async-std`]: https://github.com/async-rs/async-std
[`tokio`]: https://github.com/tokio-rs/tokio
[`actix`]: https://github.com/actix/actix-net
Expand All @@ -129,18 +132,18 @@ SQLx is compatible with the [`async-std`], [`tokio`] and [`actix`] runtimes; and
# PICK ONE OF THE FOLLOWING:

# tokio (no TLS)
sqlx = { version = "0.6", features = [ "runtime-tokio" ] }
sqlx = { version = "0.7", features = [ "runtime-tokio" ] }
# tokio + native-tls
sqlx = { version = "0.6", features = [ "runtime-tokio", "tls-native" ] }
sqlx = { version = "0.7", features = [ "runtime-tokio", "tls-native" ] }
# tokio + rustls
sqlx = { version = "0.6", features = [ "runtime-tokio", "tls-rustls" ] }
sqlx = { version = "0.7", features = [ "runtime-tokio", "tls-rustls" ] }

# async-std (no TLS)
sqlx = { version = "0.6", features = [ "runtime-async-std" ] }
sqlx = { version = "0.7", features = [ "runtime-async-std" ] }
# async-std + native-tls
sqlx = { version = "0.6", features = [ "runtime-async-std", "tls-native" ] }
sqlx = { version = "0.7", features = [ "runtime-async-std", "tls-native" ] }
# async-std + rustls
sqlx = { version = "0.6", features = [ "runtime-async-std", "tls-rustls" ] }
sqlx = { version = "0.7", features = [ "runtime-async-std", "tls-rustls" ] }
```

#### Cargo Feature Flags
Expand All @@ -153,25 +156,17 @@ be removed in the future.

- `runtime-async-std`: Use the `async-std` runtime without enabling a TLS backend.

- `runtime-async-std-native-tls`: Use the `async-std` runtime and `native-tls` TLS backend.
- `runtime-async-std-native-tls`: Use the `async-std` runtime and `native-tls` TLS backend (SOFT-DEPRECATED).

- `runtime-async-std-rustls`: Use the `async-std` runtime and `rustls` TLS backend.
- `runtime-async-std-rustls`: Use the `async-std` runtime and `rustls` TLS backend (SOFT-DEPRECATED).

- `runtime-tokio`: Use the `tokio` runtime without enabling a TLS backend.

- `runtime-tokio-native-tls`: Use the `tokio` runtime and `native-tls` TLS backend.

- `runtime-tokio-rustls`: Use the `tokio` runtime and `rustls` TLS backend.

- `runtime-actix`: Use the `actix` runtime without enabling a TLS backend.

- `runtime-actix-native-tls`: Use the `actix` runtime and `native-tls` TLS backend.
- `runtime-tokio-native-tls`: Use the `tokio` runtime and `native-tls` TLS backend (SOFT-DEPRECATED).

- `runtime-actix-rustls`: Use the `actix` runtime and `rustls` TLS backend.
- `runtime-tokio-rustls`: Use the `tokio` runtime and `rustls` TLS backend (SOFT-DEPRECATED).

- Actix-web is fully compatible with Tokio and so a separate runtime feature is no longer needed.
The above three features exist only for backwards compatibility, and are in fact merely aliases to their
`runtime-tokio` counterparts.

- `tls-native`: Use the `native-tls` TLS backend (OpenSSL on *nix, SChannel on Windows, Secure Transport on macOS).

Expand Down Expand Up @@ -199,8 +194,6 @@ be removed in the future.

- `bstr`: Add support for `bstr::BString`.

- `git2`: Add support for `git2::Oid`.

- `bigdecimal`: Add support for `NUMERIC` using the `bigdecimal` crate.

- `decimal`: Add support for `NUMERIC` using the `rust_decimal` crate.
Expand All @@ -209,8 +202,7 @@ be removed in the future.

- `json`: Add support for `JSON` and `JSONB` (in postgres) using the `serde_json` crate.

- `offline`: Enables building the macros in offline mode when a live database is not available (such as CI).
- Requires `sqlx-cli` installed to use. See [sqlx-cli/README.md][readme-offline].
- Offline mode is now always enabled. See [sqlx-cli/README.md][readme-offline].

[readme-offline]: sqlx-cli/README.md#enable-building-in-offline-mode-with-query

Expand Down Expand Up @@ -238,21 +230,8 @@ See the `examples/` folder for more in-depth usage.

### Quickstart

```toml
[dependencies]
# PICK ONE:
# Async-std:
sqlx = { version = "0.6", features = [ "runtime-async-std-native-tls", "postgres" ] }
async-std = { version = "1", features = [ "attributes" ] }

# Tokio:
sqlx = { version = "0.6", features = [ "runtime-tokio-native-tls" , "postgres" ] }
tokio = { version = "1", features = ["full"] }

# Actix-web:
sqlx = { version = "0.6", features = [ "runtime-actix-native-tls" , "postgres" ] }
actix-web = "4"
```
NOTE: these examples are for the coming 0.7.0 release, which is currently in an alpha cycle.
For the last stable release, 0.6.2, see [the previous verison of this document](https://github.com/launchbadge/sqlx/blob/v0.6.2/README.md).

```rust
use sqlx::postgres::PgPoolOptions;
Expand Down
11 changes: 0 additions & 11 deletions sqlx-core/src/any/connection/establish.rs

This file was deleted.

25 changes: 1 addition & 24 deletions sqlx-core/src/any/connection/executor.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use crate::any::{
Any, AnyColumn, AnyConnection, AnyQueryResult, AnyRow, AnyStatement, AnyTypeInfo,
};
use crate::database::Database;
use crate::any::{Any, AnyConnection, AnyQueryResult, AnyRow, AnyStatement, AnyTypeInfo};
use crate::describe::Describe;
use crate::error::Error;
use crate::executor::{Execute, Executor};
Expand Down Expand Up @@ -57,23 +54,3 @@ impl<'c> Executor<'c> for &'c mut AnyConnection {
self.backend.describe(sql)
}
}

fn map_describe<DB: Database>(info: Describe<DB>) -> Describe<Any>
where
AnyTypeInfo: From<DB::TypeInfo>,
AnyColumn: From<DB::Column>,
{
let parameters = match info.parameters {
None => None,
Some(Either::Right(num)) => Some(Either::Right(num)),
Some(Either::Left(params)) => {
Some(Either::Left(params.into_iter().map(Into::into).collect()))
}
};

Describe {
parameters,
nullable: info.nullable,
columns: info.columns.into_iter().map(Into::into).collect(),
}
}
10 changes: 8 additions & 2 deletions sqlx-core/src/any/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ pub use backend::AnyConnectionBackend;
use crate::transaction::Transaction;

mod backend;
mod establish;
mod executor;

/// A connection to _any_ SQLx database.
Expand All @@ -33,7 +32,14 @@ impl AnyConnection {
self.backend.name()
}

pub(crate) fn connect<DB: Database>(
pub(crate) fn connect(options: &AnyConnectOptions) -> BoxFuture<'_, crate::Result<Self>> {
Box::pin(async {
let driver = crate::any::driver::from_url(&options.database_url)?;
(driver.connect)(options).await
})
}

pub(crate) fn connect_with_db<DB: Database>(
options: &AnyConnectOptions,
) -> BoxFuture<'_, crate::Result<Self>>
where
Expand Down
13 changes: 2 additions & 11 deletions sqlx-core/src/any/driver.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
use crate::any::connection::AnyConnectionBackend;
use crate::any::{
Any, AnyArguments, AnyConnectOptions, AnyConnection, AnyQueryResult, AnyRow, AnyStatement,
AnyTypeInfo,
};
use crate::any::{AnyConnectOptions, AnyConnection};
use crate::common::DebugFn;
use crate::connection::Connection;
use crate::database::Database;
use crate::describe::Describe;
use crate::error::BoxDynError;
use crate::transaction::Transaction;
use crate::Error;
use either::Either;
use futures_core::future::BoxFuture;
use futures_core::stream::BoxStream;
use once_cell::sync::OnceCell;
use std::fmt::{Debug, Formatter};
use std::marker::PhantomData;
use url::Url;

static DRIVERS: OnceCell<&'static [AnyDriver]> = OnceCell::new();
Expand Down Expand Up @@ -52,7 +43,7 @@ impl AnyDriver {
Self {
name: DB::NAME,
url_schemes: DB::URL_SCHEMES,
connect: DebugFn(AnyConnection::connect::<DB>),
connect: DebugFn(AnyConnection::connect_with_db::<DB>),
migrate_database: None,
}
}
Expand Down
2 changes: 0 additions & 2 deletions sqlx-core/src/any/migrate.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use crate::any::driver;
use crate::any::kind::AnyKind;
use crate::any::{Any, AnyConnection};
use crate::error::Error;
use crate::migrate::{AppliedMigration, Migrate, MigrateDatabase, MigrateError, Migration};
use futures_core::future::BoxFuture;
use std::str::FromStr;
use std::time::Duration;

impl MigrateDatabase for Any {
Expand Down
3 changes: 1 addition & 2 deletions sqlx-core/src/any/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ where
{
fn encode_by_ref(&self, buf: &mut AnyArgumentBuffer<'q>) -> crate::encode::IsNull {
if let Some(value) = self {
value.encode_by_ref(buf);
crate::encode::IsNull::No
value.encode_by_ref(buf)
} else {
buf.0.push(AnyValueKind::Null);
crate::encode::IsNull::Yes
Expand Down
2 changes: 1 addition & 1 deletion sqlx-core/src/any/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl ConnectOptions for AnyConnectOptions {

#[inline]
fn connect(&self) -> BoxFuture<'_, Result<AnyConnection, Error>> {
Box::pin(AnyConnection::establish(self))
AnyConnection::connect(self)
}

fn log_statements(mut self, level: LevelFilter) -> Self {
Expand Down
8 changes: 1 addition & 7 deletions sqlx-core/src/any/value.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
use std::borrow::Cow;
use std::marker::PhantomData;
use std::num::TryFromIntError;

use crate::any::error::mismatched_types;
use crate::any::{Any, AnyTypeInfo, AnyTypeInfoKind};
use crate::database::{Database, HasValueRef};
use crate::decode::Decode;
use crate::error::{BoxDynError, Error};
use crate::io::Encode;
use crate::type_info::TypeInfo;
use crate::error::BoxDynError;
use crate::types::Type;
use crate::value::{Value, ValueRef};

Expand Down
2 changes: 1 addition & 1 deletion sqlx-core/src/net/tls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ where
#[cfg(feature = "_tls-native-tls")]
return Ok(with_socket.with_socket(tls_native_tls::handshake(socket, config).await?));

#[cfg(feature = "_tls-rustls")]
#[cfg(all(feature = "_tls-rustls", not(feature = "_tls-native-tls")))]
return Ok(with_socket.with_socket(tls_rustls::handshake(socket, config).await?));

#[cfg(not(any(feature = "_tls-native-tls", feature = "_tls-rustls")))]
Expand Down
3 changes: 1 addition & 2 deletions sqlx-core/src/net/tls/tls_rustls.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use futures_util::future;
use rustls::{Certificate, PrivateKey};
use std::io::{self, BufReader, Cursor, Read, Write};
use std::sync::Arc;
use std::task::{Context, Poll};
Expand All @@ -13,7 +12,7 @@ use rustls::{
use crate::error::Error;
use crate::io::ReadBuf;
use crate::net::tls::util::StdSocket;
use crate::net::tls::{CertificateInput, TlsConfig};
use crate::net::tls::TlsConfig;
use crate::net::Socket;

pub struct RustlsSocket<S: Socket> {
Expand Down
Loading