Skip to content

Introduce ConnectOptions to build a connection string from a builder #174

@mehcode

Description

@mehcode

As of 0.3

use sqlx::Connect;

let mut conn = PgConnection::connect("postgres://user:pass@localhost/database?sslmode=require");

Proposal

let options = ConnectOptions::new()
    .host("localhost")
    .port(5432)
    .username("user")
    .password("pass")
    .param("sslmode", "require");

let mut conn = PgConnection::connect(options).await?;
let mut conn = options.connect().await?;
let pool = PgPool::new(options).await?;
let pool = PgPool::builder().build(options).await?;
  • Introduce ConnectOptions
  • Implement TryFrom<&str> for ConnectOptions to parse URI and DSN connection strings
  • Pool and Connection construction now take O: TryInto<ConnectOptions>
  • The url crate should not be used for parsing; in particular, a schema should not be a required piece

Additional ideas:

  • Introduce database-specific option extension traits to for parameters. E.g.. PgConnectOptionsExt would provide a ssl_mode method to set the sslmode parameter.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions