Skip to content

Commit

Permalink
fix #1905 : replaced all uses of "uri" to "url" (#1906)
Browse files Browse the repository at this point in the history
* fix #1905 : replaced all uses of "uri" to "url"

* rebase commits

resolved conflicts in mod.rs

fixed conflict in options.rs

Update options.rs

Update options.rs

Update options.rs
  • Loading branch information
Romain authored and abonander committed Jun 17, 2022
1 parent 9b3b9bd commit 339e058
Show file tree
Hide file tree
Showing 19 changed files with 111 additions and 111 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,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
8 changes: 4 additions & 4 deletions sqlx-core/src/mysql/options/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,16 @@ impl FromStr for MySqlConnectOptions {

#[test]
fn it_parses_username_with_at_sign_correctly() {
let uri = "mysql://user@hostname:password@hostname:5432/database";
let opts = MySqlConnectOptions::from_str(uri).unwrap();
let url = "mysql://user@hostname:password@hostname:5432/database";
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 url = "mysql://username:p@ssw0rd@hostname:5432/database";
let opts = MySqlConnectOptions::from_str(url).unwrap();

assert_eq!(Some("p@ssw0rd".into()), opts.password);
}
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
16 changes: 8 additions & 8 deletions sqlx-core/src/postgres/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<(PgConnectOptions, String), Error> {
let mut options = PgConnectOptions::from_str(uri)?;
fn parse_for_maintenance(url: &str) -> Result<(PgConnectOptions, String), Error> {
let mut options = PgConnectOptions::from_str(url)?;

// pull out the name of the database to create
let database = options
Expand All @@ -36,9 +36,9 @@ fn parse_for_maintenance(uri: &str) -> Result<(PgConnectOptions, String), Error>
}

impl MigrateDatabase for Postgres {
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 @@ -52,9 +52,9 @@ impl MigrateDatabase for Postgres {
})
}

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 =
Expand All @@ -67,9 +67,9 @@ impl MigrateDatabase for Postgres {
})
}

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
Loading

0 comments on commit 339e058

Please sign in to comment.