-
Notifications
You must be signed in to change notification settings - Fork 218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(query-engine-common): reduce duplicated code between query-engine-node-api
and query-engine-wasm
#4521
Merged
Merged
Changes from all commits
Commits
Show all changes
192 commits
Select commit
Hold shift + click to select a range
61ef25b
feat(quaint): allow wasm32-unknown-unknown compilation; currently fai…
jkomyno 055e696
feat(quaint): split postgres connector into native and wasm submodules
jkomyno 12c6ebb
feat(quaint): split mysql connector into native and wasm submodules
jkomyno 060486d
feat(quaint): recover wasm error for mysql
jkomyno 5de1dc0
feat(quaint): split mssql connector into native and wasm submodules
jkomyno 8ecbc5c
feat(quaint): split sqlite connector into native and wasm submodules
jkomyno 45df24f
chore(quaint): fix clippy when compiling natively
jkomyno 6a1f733
chore(quaint): fix clippy when compiling to wasm32-unknown-unknown
jkomyno e61bf75
chore(quaint): update README
jkomyno 257c4c8
chore(quaint): rename "*-connector" feature flag to "*-native"
jkomyno 5ab6d96
feat(quaint): enable pure Wasm SqliteError
jkomyno ab65c95
feat(query-connect): allow wasm32-unknown-unknown compilation
jkomyno 485f6dc
Merge branch 'main' into feat/quaint-on-wasm32-unknown-unknown
jkomyno cfb5507
feat(sql-query-connector): allow wasm32-unknown-unknown compilation
jkomyno e7df5a3
chore(query-engine-wasm): add currently unused local crates to test w…
jkomyno 8c5d3dc
chore: update Cargo.lock
jkomyno 6648a88
chore: remove leftover comments
jkomyno 754746e
feat(query-core): allow wasm32-unknown-unknown compilation
jkomyno fe2fb8b
chore(sql-query-connector): fix clipppy on wasm32
jkomyno 2ffe394
Merge branch 'feat/sql-query-connector-on-wasm32-unknown-unknown' of …
jkomyno e66fb65
Merge branch 'feat/sql-query-connector-on-wasm32-unknown-unknown' int…
jkomyno 37bd8d1
chore: remove leftover comment
jkomyno 9c41dc1
chore: remove leftover comment
jkomyno b69bb84
feat(driver-adapters): enable Wasm on request-handlers
jkomyno c987dce
WIP: refactor mysql module to flatten its structure
miguelff 626bc1e
feat(quaint): flatten mssql connector module
jkomyno a9f8ba8
feat(quaint): flatten postgres connector module
jkomyno 3c1a100
feat(quaint): flatten sqlite connector module
jkomyno 7f4c8f9
chore(quaint): export all public definitions in connector "url" modules
jkomyno 95a4e28
chore(quaint): refactor tests for connectors, addressing feedback
jkomyno bacb635
chore: add comment on MysqlAsyncError
jkomyno 263bab0
chore: add comment on ffi.rs for sqlite
jkomyno 253b75d
Merge branch 'feat/quaint-on-wasm32-unknown-unknown' into feat/sql-qu…
jkomyno 414ae2b
Merge branch 'feat/quaint-on-wasm32-unknown-unknown' into feat/sql-qu…
jkomyno cd60a42
Merge branch 'feat/sql-query-connector-on-wasm32-unknown-unknown' int…
jkomyno d0f783d
Merge branch 'feat/sql-query-connector-on-wasm32-unknown-unknown' int…
jkomyno 76816fd
chore: replace awkward "super::super::" with "crate::..."
jkomyno f227e6c
Merge branch 'feat/sql-query-connector-on-wasm32-unknown-unknown' of …
jkomyno 7359a08
Merge branch 'feat/sql-query-connector-on-wasm32-unknown-unknown' of …
jkomyno 718cfe9
Merge branch 'feat/sql-query-connector-on-wasm32-unknown-unknown' int…
jkomyno f61665a
Merge branch 'feat/sql-query-connector-on-wasm32-unknown-unknown' int…
jkomyno 28c0ebc
chore: add comments around "query_core::executor::task"
jkomyno 5126a75
chore: add comments around "query_core::executor::task"
jkomyno de39d9e
chore: add "request-handlers" to "query-engine-wasm"
jkomyno 3bbe64c
Merge branch 'feat/query-core-on-wasm32-unknown-unknown' into feat/re…
jkomyno 4ed297e
Merge branch 'feat/query-core-on-wasm32-unknown-unknown' into feat/re…
jkomyno 0a705ec
chore: add wasm dependencies to Cargo workspace
jkomyno 9a599d1
feat(driver-adapters): move napi-specific code into "napi" module, pr…
jkomyno 3c7a778
feat(driver-adapters): extracted platform-agnostic "DriverAdapterErro…
jkomyno 23bf487
chore(driver-adapters): add "driver-adapters" to "query-engine-wasm"
jkomyno 4424d4b
feat(driver-adapters): add Wasm-specific "async_js_function"
jkomyno 9b60a18
feat(driver-adapters): extracted common types to "driver_adapters::ty…
jkomyno 1eafb3d
feat(driver-adapters): extracted "TryFrom<JSResultSet> for QuaintResu…
jkomyno cc117e2
feat(driver-adapters): allow feature-complete Wasm compilation of "dr…
jkomyno d7a799d
feat(driver-adapters): plug "driver-adapters" to "query-engine-wasm"
jkomyno c72c377
chore: remove .cargo, add it to .gitignore
jkomyno 33cdf77
Merge branch 'main' into feat/sql-query-connector-on-wasm32-unknown-u…
jkomyno 2dd3f02
Merge branch 'main' into feat/query-core-on-wasm32-unknown-unknown
jkomyno 2afeddc
Merge branch 'feat/sql-query-connector-on-wasm32-unknown-unknown' int…
jkomyno 2339b31
chore: move "task" module into its own file
jkomyno edf0f4e
Merge branch 'main' into feat/query-core-on-wasm32-unknown-unknown
jkomyno 5976ab1
Merge branch 'feat/query-core-on-wasm32-unknown-unknown' into feat/re…
jkomyno 96cd8ca
fix(driver-adapters): ci for "request-handlers"
jkomyno 3541054
fix(driver-adapters): ci for "request-handlers"
jkomyno e79cb1f
Merge branch 'main' into feat/sql-query-connector-on-wasm32-unknown-u…
jkomyno e52500f
Merge branch 'feat/sql-query-connector-on-wasm32-unknown-unknown' int…
jkomyno 2c70d12
Merge branch 'feat/query-core-on-wasm32-unknown-unknown' into feat/re…
jkomyno 91d8e5f
chore: fix conflicts from "main"
jkomyno 30d2907
Merge branch 'feat/request-handlers-on-wasm32-unknown-unknown' into f…
jkomyno 0795a6a
fix(driver-adapters): clippy compile error on "query-engine-wasm"
jkomyno 22113ca
chore(driver-adapters): fix conflicting library name warning on "carg…
jkomyno b53efbb
chore: merge main, fix conflicts
jkomyno 9c8bd20
chore: fix conflicts
jkomyno fb92bbb
chore: fixed some clippy warnings
jkomyno 3c592e1
chore: add .cargo to .gitignore
jkomyno 8529b8c
feat(query-engine-wasm): ported some logic from query-engine-node-api…
jkomyno a82584a
chore: merge main, fix conflicts
jkomyno a819ff9
chore: merge main, fix conflicts
jkomyno d276f3d
Add connect/disconnect
SevInf f4897f5
Merge branch 'feat/driver-adapters-on-wasm32-unknown-unknown' into fe…
janpio 9818aee
chore: merge main, fix conflicts
jkomyno 988e528
chore: merge driver-adapters, fix conflicts
jkomyno d054114
fix: remove tokio-induced panic in "connect"
jkomyno d6d09d6
feat: remove ducktor
jkomyno 2347cb1
feat(driver-adapters): remove "queryable" into its own module
jkomyno a57ecf5
chore: merge driver-adapters, fix conflicts
jkomyno a004fe6
Couple of fixes
SevInf 49271f6
Fix `Instant::now` usage
SevInf 0a605a5
Merge branch 'feat/query-engine-wasm32-unknown-unknown' of github.com…
jkomyno 82afce4
fix(driver-adapters): understand "flavour" and adjust casing in "JSRe…
jkomyno bbae4e3
feat(driver-adapters): add some Into traits for "JsResult"
jkomyno 40520fd
Merge branch 'feat/driver-adapters-on-wasm32-unknown-unknown' into fe…
jkomyno 77a79fa
Fix JSResult parsing
SevInf 6b60c8f
Reorganize example
SevInf 521b3ab
Fix some of the warnings
SevInf 272228e
Remove unused file
SevInf 39b2489
Fix WASM transaction binding
SevInf b589b1f
Cleanup
SevInf e56b723
feat(driver-adapters): fix enum parsing, add "wasm-rs-dbg" crate for …
jkomyno 61add9e
chore(driver-adapters): remove unused "src/wasm/queryable.rs"
jkomyno fb365ea
chore(driver-adapters): add "createOne" and "driverAdapters" preview …
jkomyno 7570e8c
chore(driver-adapters): add wasm-bindgen-test example
jkomyno 0bc9530
Merge branch 'feat/query-engine-wasm32-unknown-unknown' of github.com…
jkomyno d3b1ae9
chore(driver-adapters): update Cargo.lock
jkomyno 11526ce
Handle non-promise return values
SevInf f02bd0e
Merge remote-tracking branch 'origin/main' into feat/query-engine-was…
SevInf ab2937a
Run tests on WASM
SevInf 586c5a4
feat(core): allow Drop'ing futures running in loop in wasm32-* via co…
jkomyno 68719a3
feat(chore): add Arc<DriverAdapter> comment
jkomyno 8173e61
feat(chore): re-enable previous "disconnect()"
jkomyno fc2bd7f
feat(chore): update example.js
jkomyno 5b352ef
Merge branch 'feat/query-engine-wasm32-unknown-unknown' of github.com…
jkomyno 20d8a40
fix(query-engine-node-api): fix compilation errors
jkomyno 18a8127
Update cuid
SevInf d04804d
Remove one more isntant usage
SevInf aa5af56
chore: merge main, fix conflicts
jkomyno 7825048
chore(driver-adapters): simplify async_js_function API
jkomyno 6bedf79
chore(driver-adapters): unify napi/wasm errors into "crate::JsResult"
jkomyno 56fc689
chore(driver-adapters): continue unifying napi/wasm functions
jkomyno 1474f7b
chore(driver-adapters): unify napi/wasm logic for proxy
jkomyno d9b8e57
chore(driver-adapters): unify napi/wasm logic queryable.rs and proxy.rs
jkomyno 2ac6fb0
chore: merge main, fix conflicts
jkomyno 7a77d97
chore(driver-adapters): unify napi/wasm logic for transaction.rs
jkomyno 91bd696
chore(driver-adapters): clippy fixes
jkomyno 50f8601
chore(driver-adapters): cli
jkomyno e1867df
chore: remove dbg! output
jkomyno 2dd8159
chore: remove dbg! output
jkomyno 3d82368
Fix itx panic
SevInf e5c9716
Remove unused import
SevInf 08accae
Fix hanging itx
SevInf 269998d
fix insta tests
SevInf a063244
feat(query-engine-wasm): enable tracing and bits of telemetry
jkomyno 917c7d5
Merge branch 'feat/query-engine-wasm32-unknown-unknown' of github.com…
jkomyno bec8bc3
chore: clippy
jkomyno 715c87f
Fix panic kills running engine in query-engine-tests (#4499)
ad9b485
chore: fix conflicts
jkomyno 77e1027
Fix duplicate snapshots in json_filters test
SevInf f63661b
Size low hanging fruits
SevInf c592c88
feat(driver-adapters): serialize empty values as "null" rather than "…
jkomyno 74b4415
Merge branch 'feat/query-engine-wasm32-unknown-unknown' of github.com…
jkomyno 8b920f5
chore: fixed query-engine-node-api build
jkomyno a34f74e
chore: bumped wasm-bindgen version to 0.2.89
jkomyno c87bbb2
chore: clean up quaint transitive dependencies
jkomyno 60b0d8c
chore: removed wasm.rs test
jkomyno 48770da
chore: removed temporary wasm machinery
jkomyno 57ce977
chore: fix clippy
jkomyno 4d92a88
chore: remove unwrap from "sleep"
jkomyno ff7046a
chore: revert unnecessary psl change
jkomyno 0cf9b4a
chore(driver-adapters): fix unit tests
jkomyno 7e72125
Merge branch 'main' into feat/query-engine-wasm32-unknown-unknown
jkomyno dabe0e2
chore(driver-adapters): add clippy check for wasm32
jkomyno adf671d
chore(driver-adapters): add clippy check for wasm32
jkomyno 6c710ad
chore: fix clippy
jkomyno c5d644b
Merge branch 'feat/query-engine-wasm32-unknown-unknown' of github.com…
jkomyno 481ba65
Revert "chore: removed wasm.rs test"
jkomyno 998f5c1
test(driver-adapters): add byte tests for conversion
jkomyno 48b9381
Revert "Revert "chore: removed wasm.rs test""
jkomyno 22c1af0
chore(driver-adapters): merge main, fix conflicts, add wasm-napi inde…
jkomyno 1a9280e
Merge branch 'main' into feat/query-engine-wasm32-unknown-unknown
jkomyno 28c6ff9
[skip ci] chore: fix build CI check logic
jkomyno 7370d1f
Revert "[skip ci] chore: fix build CI check logic"
jkomyno f169fe7
chore: merge main, fix conflicts
jkomyno 0bc5b6c
Stop using removed method
SevInf 2a2565a
Fix broken JS
SevInf 534e757
chore(review): rename threadsafe_fn to fn_
jkomyno 05bd624
chore(review): add comment related to js_sys::Reflect in JsObjectExtern
jkomyno 3e88957
chore(review): rename SendFuture to UnsafeFuture, improving comments
jkomyno 687c23c
chore(review): use fully-specialized types for wasm/napi-specific log…
jkomyno 753e065
chore(review): rename JsResult into AdapterResult, reduce duplication…
jkomyno f902ded
chore(review): remove redudant full type qualifier
jkomyno 43b5146
chore(review): revert changes to psl-core
jkomyno 0257292
chore(review): improve comments on js.rs
jkomyno 9a99fd2
Test fixes for NAPI tests (#4515)
e6dc74f
chore(review): comment on spawn_controlled actors, add error tracing …
jkomyno bd0612c
chore(review): remove unused dependency
jkomyno 7f92ada
chore: fix conflicts
jkomyno 4100e5b
chore(review): move wasm/napi-specific task JoinHandle stuff to cross…
jkomyno 7d0d0bf
feat(query-engine-common): reduce duplicated code between "query-engi…
jkomyno c245720
Merge branch 'main' into feat/query-engine-wasm32-unknown-unknown
jkomyno 2ae7131
Merge branch 'feat/query-engine-wasm32-unknown-unknown' into feat/que…
jkomyno 728489a
Merge branch 'main' into feat/query-engine-wasm32-unknown-unknown
jkomyno 3ba08e2
Merge branch 'main' into feat/query-engine-wasm32-unknown-unknown
jkomyno 4a9af24
Merge branch 'feat/query-engine-wasm32-unknown-unknown' into feat/que…
jkomyno c7c8586
qe-wasm: Partially fix tests (#4517)
SevInf 14ceb7c
qe-wasm: Fix RNG on Node 18 in a test runner (#4526)
SevInf ba03e1a
Merge branch 'feat/query-engine-wasm32-unknown-unknown' into feat/que…
jkomyno ad26b19
chore: merge main, fix conflicts
jkomyno 1af7189
feat(query-engine-common): move more stuff to "query-engine-common"
jkomyno 1cb6929
chore: merge main, fix conflicts, introduced too many conditional checks
jkomyno a4a16cc
feat: limit the number of conditional flags for each native-only stru…
jkomyno b8fb3ee
feat: remove unused code (supersedes https://github.com/prisma/prisma…
jkomyno 53361f0
Merge branch 'main' into feat/query-engine-common
jkomyno File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,31 @@ | ||
[package] | ||
name = "query-engine-common" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
thiserror = "1" | ||
url = "2" | ||
query-connector = { path = "../../query-engine/connectors/query-connector" } | ||
query-core = { path = "../../query-engine/core" } | ||
user-facing-errors = { path = "../user-facing-errors" } | ||
serde_json.workspace = true | ||
serde.workspace = true | ||
connection-string.workspace = true | ||
psl.workspace = true | ||
async-trait = "0.1" | ||
tracing = "0.1" | ||
tracing-subscriber = { version = "0.3" } | ||
tracing-futures = "0.2" | ||
tracing-opentelemetry = "0.17.3" | ||
opentelemetry = { version = "0.17"} | ||
|
||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies] | ||
napi.workspace = true | ||
query-engine-metrics = { path = "../../query-engine/metrics" } | ||
|
||
[target.'cfg(target_arch = "wasm32")'.dependencies] | ||
wasm-bindgen.workspace = true | ||
tsify.workspace = true |
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,158 @@ | ||
#![allow(unused_imports)] | ||
|
||
use crate::error::ApiError; | ||
use query_core::{protocol::EngineProtocol, schema::QuerySchema, QueryExecutor}; | ||
use serde::Deserialize; | ||
use std::{ | ||
collections::{BTreeMap, HashMap}, | ||
path::PathBuf, | ||
sync::Arc, | ||
}; | ||
|
||
#[cfg(target_arch = "wasm32")] | ||
use tsify::Tsify; | ||
|
||
/// The state of the engine. | ||
pub enum Inner { | ||
/// Not connected, holding all data to form a connection. | ||
Builder(EngineBuilder), | ||
/// A connected engine, holding all data to disconnect and form a new | ||
/// connection. Allows querying when on this state. | ||
Connected(ConnectedEngine), | ||
} | ||
|
||
impl Inner { | ||
/// Returns a builder if the engine is not connected | ||
pub fn as_builder(&self) -> crate::Result<&EngineBuilder> { | ||
match self { | ||
Inner::Builder(ref builder) => Ok(builder), | ||
Inner::Connected(_) => Err(ApiError::AlreadyConnected), | ||
} | ||
} | ||
|
||
/// Returns the engine if connected | ||
pub fn as_engine(&self) -> crate::Result<&ConnectedEngine> { | ||
match self { | ||
Inner::Builder(_) => Err(ApiError::NotConnected), | ||
Inner::Connected(ref engine) => Ok(engine), | ||
} | ||
} | ||
} | ||
|
||
#[cfg(not(target_arch = "wasm32"))] | ||
pub struct EngineBuilderNative { | ||
pub config_dir: PathBuf, | ||
pub env: HashMap<String, String>, | ||
} | ||
|
||
/// Everything needed to connect to the database and have the core running. | ||
pub struct EngineBuilder { | ||
pub schema: Arc<psl::ValidatedSchema>, | ||
pub engine_protocol: EngineProtocol, | ||
|
||
#[cfg(not(target_arch = "wasm32"))] | ||
pub native: EngineBuilderNative, | ||
} | ||
|
||
#[cfg(not(target_arch = "wasm32"))] | ||
pub struct ConnectedEngineNative { | ||
pub config_dir: PathBuf, | ||
pub env: HashMap<String, String>, | ||
pub metrics: Option<query_engine_metrics::MetricRegistry>, | ||
} | ||
|
||
/// Internal structure for querying and reconnecting with the engine. | ||
pub struct ConnectedEngine { | ||
pub schema: Arc<psl::ValidatedSchema>, | ||
pub query_schema: Arc<QuerySchema>, | ||
pub executor: crate::Executor, | ||
pub engine_protocol: EngineProtocol, | ||
|
||
#[cfg(not(target_arch = "wasm32"))] | ||
pub native: ConnectedEngineNative, | ||
} | ||
|
||
impl ConnectedEngine { | ||
/// The schema AST for Query Engine core. | ||
pub fn query_schema(&self) -> &Arc<QuerySchema> { | ||
&self.query_schema | ||
} | ||
|
||
/// The query executor. | ||
pub fn executor(&self) -> &(dyn QueryExecutor + Send + Sync) { | ||
self.executor.as_ref() | ||
} | ||
|
||
pub fn engine_protocol(&self) -> EngineProtocol { | ||
self.engine_protocol | ||
} | ||
} | ||
|
||
#[cfg(not(target_arch = "wasm32"))] | ||
#[derive(Debug, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct ConstructorOptionsNative { | ||
#[serde(default)] | ||
pub datasource_overrides: BTreeMap<String, String>, | ||
pub config_dir: PathBuf, | ||
#[serde(default)] | ||
pub env: serde_json::Value, | ||
#[serde(default)] | ||
pub ignore_env_var_errors: bool, | ||
} | ||
|
||
/// Parameters defining the construction of an engine. | ||
#[derive(Debug, Deserialize)] | ||
#[cfg_attr(target_arch = "wasm32", derive(Tsify))] | ||
#[cfg_attr(target_arch = "wasm32", tsify(from_wasm_abi))] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct ConstructorOptions { | ||
pub datamodel: String, | ||
pub log_level: String, | ||
#[serde(default)] | ||
pub log_queries: bool, | ||
#[serde(default)] | ||
pub engine_protocol: Option<EngineProtocol>, | ||
|
||
#[cfg(not(target_arch = "wasm32"))] | ||
#[serde(flatten)] | ||
pub native: ConstructorOptionsNative, | ||
} | ||
|
||
pub fn map_known_error(err: query_core::CoreError) -> crate::Result<String> { | ||
let user_error: user_facing_errors::Error = err.into(); | ||
let value = serde_json::to_string(&user_error)?; | ||
|
||
Ok(value) | ||
} | ||
|
||
pub fn stringify_env_values(origin: serde_json::Value) -> crate::Result<HashMap<String, String>> { | ||
use serde_json::Value; | ||
|
||
let msg = match origin { | ||
Value::Object(map) => { | ||
let mut result: HashMap<String, String> = HashMap::new(); | ||
|
||
for (key, val) in map.into_iter() { | ||
match val { | ||
Value::Null => continue, | ||
Value::String(val) => { | ||
result.insert(key, val); | ||
} | ||
val => { | ||
result.insert(key, val.to_string()); | ||
} | ||
} | ||
} | ||
|
||
return Ok(result); | ||
} | ||
Value::Null => return Ok(Default::default()), | ||
Value::Bool(_) => "Expected an object for the env constructor parameter, got a boolean.", | ||
Value::Number(_) => "Expected an object for the env constructor parameter, got a number.", | ||
Value::String(_) => "Expected an object for the env constructor parameter, got a string.", | ||
Value::Array(_) => "Expected an object for the env constructor parameter, got an array.", | ||
}; | ||
|
||
Err(ApiError::JsonDecode(msg.to_string())) | ||
} |
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,104 @@ | ||
use psl::diagnostics::Diagnostics; | ||
use query_connector::error::ConnectorError; | ||
use query_core::CoreError; | ||
use thiserror::Error; | ||
|
||
#[derive(Debug, Error)] | ||
pub enum ApiError { | ||
#[error("{:?}", _0)] | ||
Conversion(Diagnostics, String), | ||
|
||
#[error("{}", _0)] | ||
Configuration(String), | ||
|
||
#[error("{}", _0)] | ||
Core(CoreError), | ||
|
||
#[error("{}", _0)] | ||
Connector(ConnectorError), | ||
|
||
#[error("Can't modify an already connected engine.")] | ||
AlreadyConnected, | ||
|
||
#[error("Engine is not yet connected.")] | ||
NotConnected, | ||
|
||
#[error("{}", _0)] | ||
JsonDecode(String), | ||
} | ||
|
||
impl From<ApiError> for user_facing_errors::Error { | ||
fn from(err: ApiError) -> Self { | ||
use std::fmt::Write as _; | ||
|
||
match err { | ||
ApiError::Connector(ConnectorError { | ||
user_facing_error: Some(err), | ||
.. | ||
}) => err.into(), | ||
ApiError::Conversion(errors, dml_string) => { | ||
let mut full_error = errors.to_pretty_string("schema.prisma", &dml_string); | ||
write!(full_error, "\nValidation Error Count: {}", errors.errors().len()).unwrap(); | ||
|
||
user_facing_errors::Error::from(user_facing_errors::KnownError::new( | ||
user_facing_errors::common::SchemaParserError { full_error }, | ||
)) | ||
} | ||
ApiError::Core(error) => user_facing_errors::Error::from(error), | ||
other => user_facing_errors::Error::new_non_panic_with_current_backtrace(other.to_string()), | ||
} | ||
} | ||
} | ||
|
||
impl ApiError { | ||
pub fn conversion(diagnostics: Diagnostics, dml: impl ToString) -> Self { | ||
Self::Conversion(diagnostics, dml.to_string()) | ||
} | ||
|
||
pub fn configuration(msg: impl ToString) -> Self { | ||
Self::Configuration(msg.to_string()) | ||
} | ||
} | ||
|
||
impl From<CoreError> for ApiError { | ||
fn from(e: CoreError) -> Self { | ||
match e { | ||
CoreError::ConfigurationError(message) => Self::Configuration(message), | ||
core_error => Self::Core(core_error), | ||
} | ||
} | ||
} | ||
|
||
impl From<ConnectorError> for ApiError { | ||
fn from(e: ConnectorError) -> Self { | ||
Self::Connector(e) | ||
} | ||
} | ||
|
||
impl From<url::ParseError> for ApiError { | ||
fn from(e: url::ParseError) -> Self { | ||
Self::configuration(format!("Error parsing connection string: {e}")) | ||
} | ||
} | ||
|
||
impl From<connection_string::Error> for ApiError { | ||
fn from(e: connection_string::Error) -> Self { | ||
Self::configuration(format!("Error parsing connection string: {e}")) | ||
} | ||
} | ||
|
||
impl From<serde_json::Error> for ApiError { | ||
fn from(e: serde_json::Error) -> Self { | ||
Self::JsonDecode(format!("{e}")) | ||
} | ||
} | ||
|
||
#[cfg(not(target_arch = "wasm32"))] | ||
impl From<ApiError> for napi::Error { | ||
fn from(e: ApiError) -> Self { | ||
let user_facing = user_facing_errors::Error::from(e); | ||
let message = serde_json::to_string(&user_facing).unwrap(); | ||
|
||
napi::Error::from_reason(message) | ||
} | ||
} | ||
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,9 @@ | ||
//! Common definitions and functions for the Query Engine library. | ||
|
||
pub mod engine; | ||
pub mod error; | ||
pub mod logger; | ||
pub mod tracer; | ||
|
||
pub type Result<T> = std::result::Result<T, error::ApiError>; | ||
pub type Executor = Box<dyn query_core::QueryExecutor + Send + Sync>; |
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,3 @@ | ||
pub trait StringCallback { | ||
fn call(&self, message: String) -> Result<(), String>; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rust doesn't allow us to implement traits like this one outside the module
ApiError
was declared in. This conditional flag is more convenient than having to wrapApiError
into a newtype in thequery-engine-*/**/engine.rs
files.