Skip to content

Commit

Permalink
feat(driver-adapters): remove fallback for "provider"/"flavour" (#4554)
Browse files Browse the repository at this point in the history
* feat(driver-adapters): remove fallback for "provider"/"flavour"

* chore: fix clippy
  • Loading branch information
jkomyno authored Dec 13, 2023
1 parent 8a6f85f commit 35b101e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
4 changes: 2 additions & 2 deletions query-engine/driver-adapters/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ mod arch {
}
}

pub(crate) fn has_named_property(object: &super::wasm::JsObjectExtern, name: &str) -> JsResult<bool> {
fn has_named_property(object: &super::wasm::JsObjectExtern, name: &str) -> JsResult<bool> {
js_sys::Reflect::has(object, &JsString::from_str(name).unwrap().into())
}

Expand Down Expand Up @@ -130,7 +130,7 @@ mod arch {
}
}

pub(crate) fn has_named_property(object: &::napi::JsObject, name: &str) -> JsResult<bool> {
fn has_named_property(object: &::napi::JsObject, name: &str) -> JsResult<bool> {
object.has_named_property(name)
}

Expand Down
14 changes: 3 additions & 11 deletions query-engine/driver-adapters/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use crate::send_future::UnsafeFuture;
use crate::types::JsConnectionInfo;
pub use crate::types::{ColumnType, JSResultSet, Query, TransactionOptions};
use crate::{
from_js_value, get_named_property, get_optional_named_property, has_named_property, to_rust_str, AdapterMethod,
JsObject, JsResult, JsString, JsTransaction,
from_js_value, get_named_property, get_optional_named_property, to_rust_str, AdapterMethod, JsObject, JsResult,
JsString, JsTransaction,
};

use futures::Future;
Expand Down Expand Up @@ -56,15 +56,7 @@ pub(crate) struct TransactionProxy {

impl CommonProxy {
pub fn new(object: &JsObject) -> JsResult<Self> {
// Background info:
// - the provider was previously called "flavour", so we provide a temporary fallback for third-party providers
// to give them time to adapt
// - reading a named property that does not exist yields a panic, despite the `Result<_, _>` return type
let provider: JsString = if has_named_property(object, "provider")? {
get_named_property(object, "provider")?
} else {
get_named_property(object, "flavour")?
};
let provider: JsString = get_named_property(object, "provider")?;

Ok(Self {
query_raw: get_named_property(object, "queryRaw")?,
Expand Down

0 comments on commit 35b101e

Please sign in to comment.