Skip to content
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

fix #1905 : replaced all uses of "uri" to "url" #1906

Merged
merged 2 commits into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ Fix docs.rs build by enabling a runtime feature in the docs.rs metadata in `Carg

### Added

- [[#174]] Inroduce a builder to construct connections to bypass the URI parsing
- [[#174]] Inroduce a builder to construct connections to bypass the URL parsing

```rust
// MSSQL
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ with C, those interactions are `unsafe`.

- Nested transactions with support for save points.

- `Any` database driver for changing the database driver at runtime. An `AnyPool` connects to the driver indicated by the URI scheme.
- `Any` database driver for changing the database driver at runtime. An `AnyPool` connects to the driver indicated by the URL scheme.

## Install

Expand Down
2 changes: 1 addition & 1 deletion sqlx-core/src/any/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::any::{
use crate::database::{Database, HasArguments, HasStatement, HasStatementCache, HasValueRef};

/// Opaque database driver. Capable of being used in place of any SQLx database driver. The actual
/// driver used will be selected at runtime, from the connection uri.
/// driver used will be selected at runtime, from the connection url.
#[derive(Debug)]
pub struct Any;

Expand Down
22 changes: 11 additions & 11 deletions sqlx-core/src/any/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,49 +19,49 @@ pub enum AnyKind {
impl FromStr for AnyKind {
type Err = Error;

fn from_str(uri: &str) -> Result<Self, Self::Err> {
match uri {
fn from_str(url: &str) -> Result<Self, Self::Err> {
match url {
#[cfg(feature = "postgres")]
_ if uri.starts_with("postgres:") || uri.starts_with("postgresql:") => {
_ if url.starts_with("postgres:") || url.starts_with("postgresql:") => {
Ok(AnyKind::Postgres)
}

#[cfg(not(feature = "postgres"))]
_ if uri.starts_with("postgres:") || uri.starts_with("postgresql:") => {
_ if url.starts_with("postgres:") || url.starts_with("postgresql:") => {
Err(Error::Configuration("database URL has the scheme of a PostgreSQL database but the `postgres` feature is not enabled".into()))
}

#[cfg(feature = "mysql")]
_ if uri.starts_with("mysql:") || uri.starts_with("mariadb:") => {
_ if url.starts_with("mysql:") || url.starts_with("mariadb:") => {
Ok(AnyKind::MySql)
}

#[cfg(not(feature = "mysql"))]
_ if uri.starts_with("mysql:") || uri.starts_with("mariadb:") => {
_ if url.starts_with("mysql:") || url.starts_with("mariadb:") => {
Err(Error::Configuration("database URL has the scheme of a MySQL database but the `mysql` feature is not enabled".into()))
}

#[cfg(feature = "sqlite")]
_ if uri.starts_with("sqlite:") => {
_ if url.starts_with("sqlite:") => {
Ok(AnyKind::Sqlite)
}

#[cfg(not(feature = "sqlite"))]
_ if uri.starts_with("sqlite:") => {
_ if url.starts_with("sqlite:") => {
Err(Error::Configuration("database URL has the scheme of a SQLite database but the `sqlite` feature is not enabled".into()))
}

#[cfg(feature = "mssql")]
_ if uri.starts_with("mssql:") || uri.starts_with("sqlserver:") => {
_ if url.starts_with("mssql:") || url.starts_with("sqlserver:") => {
Ok(AnyKind::Mssql)
}

#[cfg(not(feature = "mssql"))]
_ if uri.starts_with("mssql:") || uri.starts_with("sqlserver:") => {
_ if url.starts_with("mssql:") || url.starts_with("sqlserver:") => {
Err(Error::Configuration("database URL has the scheme of a MSSQL database but the `mssql` feature is not enabled".into()))
}

_ => Err(Error::Configuration(format!("unrecognized database url: {:?}", uri).into()))
_ => Err(Error::Configuration(format!("unrecognized database url: {:?}", url).into()))
}
}
}
30 changes: 15 additions & 15 deletions sqlx-core/src/any/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,53 +8,53 @@ use std::str::FromStr;
use std::time::Duration;

impl MigrateDatabase for Any {
fn create_database(uri: &str) -> BoxFuture<'_, Result<(), Error>> {
fn create_database(url: &str) -> BoxFuture<'_, Result<(), Error>> {
Box::pin(async move {
match AnyKind::from_str(uri)? {
match AnyKind::from_str(url)? {
#[cfg(feature = "postgres")]
AnyKind::Postgres => crate::postgres::Postgres::create_database(uri).await,
AnyKind::Postgres => crate::postgres::Postgres::create_database(url).await,

#[cfg(feature = "sqlite")]
AnyKind::Sqlite => crate::sqlite::Sqlite::create_database(uri).await,
AnyKind::Sqlite => crate::sqlite::Sqlite::create_database(url).await,

#[cfg(feature = "mysql")]
AnyKind::MySql => crate::mysql::MySql::create_database(uri).await,
AnyKind::MySql => crate::mysql::MySql::create_database(url).await,

#[cfg(feature = "mssql")]
AnyKind::Mssql => unimplemented!(),
}
})
}

fn database_exists(uri: &str) -> BoxFuture<'_, Result<bool, Error>> {
fn database_exists(url: &str) -> BoxFuture<'_, Result<bool, Error>> {
Box::pin(async move {
match AnyKind::from_str(uri)? {
match AnyKind::from_str(url)? {
#[cfg(feature = "postgres")]
AnyKind::Postgres => crate::postgres::Postgres::database_exists(uri).await,
AnyKind::Postgres => crate::postgres::Postgres::database_exists(url).await,

#[cfg(feature = "sqlite")]
AnyKind::Sqlite => crate::sqlite::Sqlite::database_exists(uri).await,
AnyKind::Sqlite => crate::sqlite::Sqlite::database_exists(url).await,

#[cfg(feature = "mysql")]
AnyKind::MySql => crate::mysql::MySql::database_exists(uri).await,
AnyKind::MySql => crate::mysql::MySql::database_exists(url).await,

#[cfg(feature = "mssql")]
AnyKind::Mssql => unimplemented!(),
}
})
}

fn drop_database(uri: &str) -> BoxFuture<'_, Result<(), Error>> {
fn drop_database(url: &str) -> BoxFuture<'_, Result<(), Error>> {
Box::pin(async move {
match AnyKind::from_str(uri)? {
match AnyKind::from_str(url)? {
#[cfg(feature = "postgres")]
AnyKind::Postgres => crate::postgres::Postgres::drop_database(uri).await,
AnyKind::Postgres => crate::postgres::Postgres::drop_database(url).await,

#[cfg(feature = "sqlite")]
AnyKind::Sqlite => crate::sqlite::Sqlite::drop_database(uri).await,
AnyKind::Sqlite => crate::sqlite::Sqlite::drop_database(url).await,

#[cfg(feature = "mysql")]
AnyKind::MySql => crate::mysql::MySql::drop_database(uri).await,
AnyKind::MySql => crate::mysql::MySql::drop_database(url).await,

#[cfg(feature = "mssql")]
AnyKind::Mssql => unimplemented!(),
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 @@ -20,7 +20,7 @@ use crate::any::kind::AnyKind;
use crate::mssql::MssqlConnectOptions;

/// Opaque options for connecting to a database. These may only be constructed by parsing from
/// a connection uri.
/// a connection url.
///
/// ```text
/// postgres://postgres:password@localhost/database
Expand Down
2 changes: 1 addition & 1 deletion sqlx-core/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
//! let conn = AnyConnection::connect("sqlite://file.db").await?;
//!
//! // connect to Postgres, no code change
//! // required, decided by the scheme of the URI
//! // required, decided by the scheme of the URL
//! let conn = AnyConnection::connect("postgres://localhost/sqlx").await?;
//! ```
Expand Down
12 changes: 6 additions & 6 deletions sqlx-core/src/migrate/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ use futures_core::future::BoxFuture;
use std::time::Duration;

pub trait MigrateDatabase {
// create database in uri
// create database in url
// uses a maintenance database depending on driver
fn create_database(uri: &str) -> BoxFuture<'_, Result<(), Error>>;
fn create_database(url: &str) -> BoxFuture<'_, Result<(), Error>>;

// check if the database in uri exists
// check if the database in url exists
// uses a maintenance database depending on driver
fn database_exists(uri: &str) -> BoxFuture<'_, Result<bool, Error>>;
fn database_exists(url: &str) -> BoxFuture<'_, Result<bool, Error>>;

// drop database in uri
// drop database in url
// uses a maintenance database depending on driver
fn drop_database(uri: &str) -> BoxFuture<'_, Result<(), Error>>;
fn drop_database(url: &str) -> BoxFuture<'_, Result<(), Error>>;
}

// 'e = Executor
Expand Down
8 changes: 4 additions & 4 deletions sqlx-core/src/mssql/options/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ impl FromStr for MssqlConnectOptions {

#[test]
fn it_parses_username_with_at_sign_correctly() {
let uri = "mysql://user@hostname:password@hostname:5432/database";
let opts = MssqlConnectOptions::from_str(uri).unwrap();
let url = "mysql://user@hostname:password@hostname:5432/database";
let opts = MssqlConnectOptions::from_str(url).unwrap();

assert_eq!("user@hostname", &opts.username);
}

#[test]
fn it_parses_password_with_non_ascii_chars_correctly() {
let uri = "mysql://username:p@ssw0rd@hostname:5432/database";
let opts = MssqlConnectOptions::from_str(uri).unwrap();
let url = "mysql://username:p@ssw0rd@hostname:5432/database";
let opts = MssqlConnectOptions::from_str(url).unwrap();

assert_eq!(Some("p@ssw0rd".into()), opts.password);
}
16 changes: 8 additions & 8 deletions sqlx-core/src/mysql/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use std::str::FromStr;
use std::time::Duration;
use std::time::Instant;

fn parse_for_maintenance(uri: &str) -> Result<(MySqlConnectOptions, String), Error> {
let mut options = MySqlConnectOptions::from_str(uri)?;
fn parse_for_maintenance(url: &str) -> Result<(MySqlConnectOptions, String), Error> {
let mut options = MySqlConnectOptions::from_str(url)?;

let database = if let Some(database) = &options.database {
database.to_owned()
Expand All @@ -31,9 +31,9 @@ fn parse_for_maintenance(uri: &str) -> Result<(MySqlConnectOptions, String), Err
}

impl MigrateDatabase for MySql {
fn create_database(uri: &str) -> BoxFuture<'_, Result<(), Error>> {
fn create_database(url: &str) -> BoxFuture<'_, Result<(), Error>> {
Box::pin(async move {
let (options, database) = parse_for_maintenance(uri)?;
let (options, database) = parse_for_maintenance(url)?;
let mut conn = options.connect().await?;

let _ = conn
Expand All @@ -44,9 +44,9 @@ impl MigrateDatabase for MySql {
})
}

fn database_exists(uri: &str) -> BoxFuture<'_, Result<bool, Error>> {
fn database_exists(url: &str) -> BoxFuture<'_, Result<bool, Error>> {
Box::pin(async move {
let (options, database) = parse_for_maintenance(uri)?;
let (options, database) = parse_for_maintenance(url)?;
let mut conn = options.connect().await?;

let exists: bool = query_scalar(
Expand All @@ -60,9 +60,9 @@ impl MigrateDatabase for MySql {
})
}

fn drop_database(uri: &str) -> BoxFuture<'_, Result<(), Error>> {
fn drop_database(url: &str) -> BoxFuture<'_, Result<(), Error>> {
Box::pin(async move {
let (options, database) = parse_for_maintenance(uri)?;
let (options, database) = parse_for_maintenance(url)?;
let mut conn = options.connect().await?;

let _ = conn
Expand Down
4 changes: 2 additions & 2 deletions sqlx-core/src/mysql/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub use ssl_mode::MySqlSslMode;

/// Options and flags which can be used to configure a MySQL connection.
///
/// A value of `MySqlConnectOptions` can be parsed from a connection URI,
/// A value of `MySqlConnectOptions` can be parsed from a connection URL,
/// as described by [MySQL](https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-reference-jdbc-url-format.html).
///
/// The generic format of the connection URL:
Expand Down Expand Up @@ -37,7 +37,7 @@ pub use ssl_mode::MySqlSslMode;
/// # fn main() {
/// # #[cfg(feature = "_rt-async-std")]
/// # sqlx_rt::async_std::task::block_on::<_, Result<(), Error>>(async move {
/// // URI connection string
/// // URL connection string
/// let conn = MySqlConnection::connect("mysql://root:password@localhost/db").await?;
///
/// // Manually-constructed options
Expand Down
4 changes: 2 additions & 2 deletions sqlx-core/src/mysql/options/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ impl FromStr for MySqlConnectOptions {
#[test]
fn it_parses_username_with_at_sign_correctly() {
let uri = "mysql://user@hostname:password@hostname:5432/database";
romsto marked this conversation as resolved.
Show resolved Hide resolved
let opts = MySqlConnectOptions::from_str(uri).unwrap();
let opts = MySqlConnectOptions::from_str(url).unwrap();

assert_eq!("user@hostname", &opts.username);
}

#[test]
fn it_parses_password_with_non_ascii_chars_correctly() {
let uri = "mysql://username:p@ssw0rd@hostname:5432/database";
let opts = MySqlConnectOptions::from_str(uri).unwrap();
let opts = MySqlConnectOptions::from_str(url).unwrap();

assert_eq!(Some("p@ssw0rd".into()), opts.password);
}
14 changes: 7 additions & 7 deletions sqlx-core/src/pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,9 @@ pub struct CloseEvent {

impl<DB: Database> Pool<DB> {
/// Creates a new connection pool with a default pool configuration and
/// the given connection URI; and, immediately establishes one connection.
pub async fn connect(uri: &str) -> Result<Self, Error> {
PoolOptions::<DB>::new().connect(uri).await
/// the given connection URL; and, immediately establishes one connection.
pub async fn connect(url: &str) -> Result<Self, Error> {
PoolOptions::<DB>::new().connect(url).await
}

/// Creates a new connection pool with a default pool configuration and
Expand All @@ -265,10 +265,10 @@ impl<DB: Database> Pool<DB> {
}

/// Creates a new connection pool with a default pool configuration and
/// the given connection URI; and, will establish a connections as the pool
/// the given connection URL; and, will establish a connections as the pool
/// starts to be used.
pub fn connect_lazy(uri: &str) -> Result<Self, Error> {
PoolOptions::<DB>::new().connect_lazy(uri)
pub fn connect_lazy(url: &str) -> Result<Self, Error> {
PoolOptions::<DB>::new().connect_lazy(url)
}

/// Creates a new connection pool with a default pool configuration and
Expand Down Expand Up @@ -449,7 +449,7 @@ impl<DB: Database> Pool<DB> {
impl Pool<Any> {
/// Returns the database driver currently in-use by this `Pool`.
///
/// Determined by the connection URI.
/// Determined by the connection URL.
pub fn any_kind(&self) -> AnyKind {
self.0.connect_options.kind()
}
Expand Down
8 changes: 4 additions & 4 deletions sqlx-core/src/pool/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ impl<DB: Database> PoolOptions<DB> {
}

/// Creates a new pool from this configuration and immediately establishes one connection.
pub async fn connect(self, uri: &str) -> Result<Pool<DB>, Error> {
self.connect_with(uri.parse()?).await
pub async fn connect(self, url: &str) -> Result<Pool<DB>, Error> {
self.connect_with(url.parse()?).await
}

/// Creates a new pool from this configuration and immediately establishes one connection.
Expand All @@ -208,8 +208,8 @@ impl<DB: Database> PoolOptions<DB> {

/// Creates a new pool from this configuration and will establish a connections as the pool
/// starts to be used.
pub fn connect_lazy(self, uri: &str) -> Result<Pool<DB>, Error> {
Ok(self.connect_lazy_with(uri.parse()?))
pub fn connect_lazy(self, url: &str) -> Result<Pool<DB>, Error> {
Ok(self.connect_lazy_with(url.parse()?))
}

/// Creates a new pool from this configuration and will establish a connections as the pool
Expand Down
4 changes: 2 additions & 2 deletions sqlx-core/src/postgres/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ pub struct PgListener {
pub struct PgNotification(Notification);

impl PgListener {
pub async fn connect(uri: &str) -> Result<Self, Error> {
pub async fn connect(url: &str) -> Result<Self, Error> {
// Create a pool of 1 without timeouts (as they don't apply here)
// We only use the pool to handle re-connections
let pool = PoolOptions::<Postgres>::new()
.max_connections(1)
.max_lifetime(None)
.idle_timeout(None)
.connect(uri)
.connect(url)
.await?;

let mut this = Self::connect_with(&pool).await?;
Expand Down
Loading