-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
driver-adapters: Don't read URL from schema (#4548)
* driver-adapters: Don't read URL from schema By desing, adapter itself is responsible for establishing connection and users are expected to provide url to JS driver manually. Yet, we continued to validate and read URL from schema file upon initialization. Information, derived from connection URL used in a bunch of places in quaint and other crates. Most of them are optional, such as error messages. However, one important thing - default schema name - is used for building SQL queries. We need an alternative way to provide that information, that does not include URL parsing. This PR expands adapter API by adding optional method, `getConnectionInfo`. Right now, it can only return an object wiht `schemaName` property. If it does, this name will be used as a prefix for SQL queries. If it does not, or `getConnectionInfo` is ommited, defaults will be used: - `main` for postgres and sqlite - `mysql` for mysql Generally, it is up for adapter to decide on where to get this info from: if URL on JS side contains it, it might get it from there or it can have an optional constructor option with a schema name. This PR will require a follow up on JS side too: at the minimum, expanding public interface of a driver. Contributes to prisma/prisma-orm#662 * Fix test runner * Fix clippy & migrate tests * Remove commented out code * Correct default schema for postgres * Provide schema URL to the driver adapters DRIVER_ADAPTERS_BRANCH=feat/getConnectionInfo * Rename SQLITE_DEFAULT_SCHEMA to DATABASE * Add a way to call JS functions without promises to both WASM and NAPI * Use newer adapters
- Loading branch information
Showing
34 changed files
with
319 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use async_trait::async_trait; | ||
|
||
use super::{SqlFamily, TransactionCapable}; | ||
|
||
#[derive(Debug, Clone)] | ||
pub struct ExternalConnectionInfo { | ||
pub sql_family: SqlFamily, | ||
pub schema_name: String, | ||
} | ||
|
||
impl ExternalConnectionInfo { | ||
pub fn new(sql_family: SqlFamily, schema_name: String) -> Self { | ||
ExternalConnectionInfo { | ||
sql_family, | ||
schema_name, | ||
} | ||
} | ||
} | ||
|
||
#[async_trait] | ||
pub trait ExternalConnector: TransactionCapable { | ||
async fn get_connection_info(&self) -> crate::Result<ExternalConnectionInfo>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
//! Wasm-compatible definitions for the MySQL connector. | ||
//! This module is only available with the `mysql` feature. | ||
mod defaults; | ||
pub(crate) mod error; | ||
pub(crate) mod url; | ||
|
||
pub use self::url::*; | ||
pub use error::MysqlError; | ||
|
||
pub use defaults::*; | ||
#[cfg(feature = "mysql-native")] | ||
pub(crate) mod native; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub const DEFAULT_MYSQL_DB: &str = "mysql"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub const DEFAULT_POSTGRES_SCHEMA: &str = "public"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub const DEFAULT_SQLITE_DATABASE: &str = "main"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
//! A "prelude" for users of the `quaint` crate. | ||
pub use crate::ast::*; | ||
pub use crate::connector::{ | ||
ConnectionInfo, DefaultTransaction, Queryable, ResultRow, ResultSet, SqlFamily, TransactionCapable, | ||
ConnectionInfo, DefaultTransaction, ExternalConnectionInfo, Queryable, ResultRow, ResultSet, SqlFamily, | ||
TransactionCapable, | ||
}; | ||
pub use crate::{col, val, values}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.