Skip to content

Commit

Permalink
chore(driver-adapters): unify napi/wasm errors into "crate::JsResult"
Browse files Browse the repository at this point in the history
  • Loading branch information
jkomyno committed Nov 27, 2023
1 parent 7825048 commit 6bedf79
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
14 changes: 14 additions & 0 deletions query-engine/driver-adapters/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,17 @@ pub mod wasm;

#[cfg(target_arch = "wasm32")]
pub use wasm::*;

#[cfg(target_arch = "wasm32")]
mod arch {
use wasm_bindgen::JsValue;

pub(crate) type JsResult<T> = core::result::Result<T, JsValue>;
}

#[cfg(not(target_arch = "wasm32"))]
mod arch {
pub(crate) type JsResult<T> = napi::Result<T>;
}

pub(crate) use arch::JsResult;
7 changes: 4 additions & 3 deletions query-engine/driver-adapters/src/napi/proxy.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub use crate::types::{ColumnType, JSResultSet, Query, TransactionOptions};
use crate::JsResult;

use super::async_js_function::AsyncJsFunction;
use super::transaction::JsTransaction;
Expand Down Expand Up @@ -43,7 +44,7 @@ pub(crate) struct TransactionProxy {
}

impl CommonProxy {
pub fn new(object: &JsObject) -> napi::Result<Self> {
pub fn new(object: &JsObject) -> JsResult<Self> {
let flavour: JsString = object.get_named_property("flavour")?;

Ok(Self {
Expand All @@ -63,7 +64,7 @@ impl CommonProxy {
}

impl DriverProxy {
pub fn new(driver_adapter: &JsObject) -> napi::Result<Self> {
pub fn new(driver_adapter: &JsObject) -> JsResult<Self> {
Ok(Self {
start_transaction: driver_adapter.get_named_property("startTransaction")?,
})
Expand All @@ -82,7 +83,7 @@ impl DriverProxy {
}

impl TransactionProxy {
pub fn new(js_transaction: &JsObject) -> napi::Result<Self> {
pub fn new(js_transaction: &JsObject) -> JsResult<Self> {
let commit = js_transaction.get_named_property("commit")?;
let rollback = js_transaction.get_named_property("rollback")?;
let options = js_transaction.get_named_property("options")?;
Expand Down
15 changes: 7 additions & 8 deletions query-engine/driver-adapters/src/wasm/proxy.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
use futures::Future;
use js_sys::{Function as JsFunction, JsString};
use tsify::Tsify;

use super::{async_js_function::AsyncJsFunction, transaction::JsTransaction};
use crate::send_future::SendFuture;
pub use crate::types::{ColumnType, JSResultSet, Query, TransactionOptions};
use crate::JsObjectExtern;
use crate::JsResult;

use super::{async_js_function::AsyncJsFunction, transaction::JsTransaction};
use futures::Future;
use js_sys::{Function as JsFunction, JsString};
use metrics::increment_gauge;
use std::sync::atomic::{AtomicBool, Ordering};
use wasm_bindgen::{prelude::wasm_bindgen, JsValue};

type JsResult<T> = core::result::Result<T, JsValue>;
use tsify::Tsify;
use wasm_bindgen::prelude::wasm_bindgen;

/// Proxy is a struct wrapping a javascript object that exhibits basic primitives for
/// querying and executing SQL (i.e. a client connector). The Proxy uses Wasm's JsFunction to
Expand Down

0 comments on commit 6bedf79

Please sign in to comment.