diff --git a/Cargo.toml b/Cargo.toml index f5cd66b3..8ff6b180 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ debug = true lto = true [workspace.package] -rust-version = "1.72" # keep in sync with flake.nix +rust-version = "1.75" # keep in sync with flake.nix [workspace.lints.clippy] useless_format = 'allow' diff --git a/edgedb-tokio/src/lib.rs b/edgedb-tokio/src/lib.rs index 6cb60db8..4827270f 100644 --- a/edgedb-tokio/src/lib.rs +++ b/edgedb-tokio/src/lib.rs @@ -133,6 +133,7 @@ mod builder; mod client; mod errors; mod options; +mod query_executor; mod sealed; pub mod state; mod transaction; @@ -145,6 +146,7 @@ pub use client::Client; pub use credentials::TlsSecurity; pub use errors::Error; pub use options::{RetryCondition, RetryOptions, TransactionOptions}; +pub use query_executor::QueryExecutor; pub use state::{ConfigDelta, GlobalsDelta}; pub use transaction::Transaction; diff --git a/edgedb-tokio/src/query_executor.rs b/edgedb-tokio/src/query_executor.rs new file mode 100644 index 00000000..13400cd8 --- /dev/null +++ b/edgedb-tokio/src/query_executor.rs @@ -0,0 +1,200 @@ +use edgedb_protocol::model::Json; +use edgedb_protocol::query_arg::QueryArgs; +use edgedb_protocol::QueryResult; +use std::future::Future; + +use crate::{Client, Error, Transaction}; + +/// Abstracts over different query executors +/// In particular &Client and &mut Transaction +pub trait QueryExecutor { + /// see [Client::query] + fn query( + self, + query: &str, + arguments: &A, + ) -> impl Future, Error>> + Send + where + A: QueryArgs, + R: QueryResult + Send; + + /// see [Client::query_single] + fn query_single( + self, + query: &str, + arguments: &A, + ) -> impl Future, Error>> + Send + where + A: QueryArgs, + R: QueryResult + Send; + + /// see [Client::query_required_single] + fn query_required_single( + self, + query: &str, + arguments: &A, + ) -> impl Future> + Send + where + A: QueryArgs, + R: QueryResult + Send; + + /// see [Client::query_json] + fn query_json( + self, + query: &str, + arguments: &impl QueryArgs, + ) -> impl Future> + Send; + + /// see [Client::query_single_json] + fn query_single_json( + &mut self, + query: &str, + arguments: &impl QueryArgs, + ) -> impl Future, Error>> + Send; + + /// see [Client::query_required_single_json] + fn query_required_single_json( + &mut self, + query: &str, + arguments: &impl QueryArgs, + ) -> impl Future>; + + /// see [Client::execute] + fn execute( + &mut self, + query: &str, + arguments: &A, + ) -> impl Future> + Send + where + A: QueryArgs; +} + +impl QueryExecutor for &Client { + fn query(self, query: &str, arguments: &A) -> impl Future, Error>> + where + A: QueryArgs, + R: QueryResult, + { + Client::query(self, query, arguments) + } + + fn query_single( + self, + query: &str, + arguments: &A, + ) -> impl Future, Error>> + where + A: QueryArgs, + R: QueryResult + Send, + { + Client::query_single(self, query, arguments) + } + + fn query_required_single( + self, + query: &str, + arguments: &A, + ) -> impl Future> + Send + where + A: QueryArgs, + R: QueryResult + Send, + { + Client::query_required_single(self, query, arguments) + } + + fn query_json( + self, + query: &str, + arguments: &impl QueryArgs, + ) -> impl Future> { + Client::query_json(self, query, arguments) + } + + fn query_single_json( + &mut self, + query: &str, + arguments: &impl QueryArgs, + ) -> impl Future, Error>> { + Client::query_single_json(self, query, arguments) + } + + fn query_required_single_json( + &mut self, + query: &str, + arguments: &impl QueryArgs, + ) -> impl Future> { + Client::query_required_single_json(self, query, arguments) + } + + fn execute(&mut self, query: &str, arguments: &A) -> impl Future> + where + A: QueryArgs, + { + Client::execute(self, query, arguments) + } +} + +impl QueryExecutor for &mut Transaction { + fn query(self, query: &str, arguments: &A) -> impl Future, Error>> + where + A: QueryArgs, + R: QueryResult, + { + Transaction::query(self, query, arguments) + } + + fn query_single( + self, + query: &str, + arguments: &A, + ) -> impl Future, Error>> + where + A: QueryArgs, + R: QueryResult, + { + Transaction::query_single(self, query, arguments) + } + + fn query_required_single( + self, + query: &str, + arguments: &A, + ) -> impl Future> + where + A: QueryArgs, + R: QueryResult, + { + Transaction::query_required_single(self, query, arguments) + } + + fn query_json( + self, + query: &str, + arguments: &impl QueryArgs, + ) -> impl Future> { + Transaction::query_json(self, query, arguments) + } + + fn query_single_json( + &mut self, + query: &str, + arguments: &impl QueryArgs, + ) -> impl Future, Error>> { + Transaction::query_single_json(self, query, arguments) + } + + fn query_required_single_json( + &mut self, + query: &str, + arguments: &impl QueryArgs, + ) -> impl Future> { + Transaction::query_required_single_json(self, query, arguments) + } + + fn execute(&mut self, query: &str, arguments: &A) -> impl Future> + where + A: QueryArgs, + { + Transaction::execute(self, query, arguments) + } +} diff --git a/flake.nix b/flake.nix index ad242959..4d253c9c 100644 --- a/flake.nix +++ b/flake.nix @@ -54,8 +54,8 @@ devShells.minimum = pkgs.mkShell { buildInputs = [ (fenix_pkgs.toolchainOf { - channel = "1.72"; # keep in sync with ./Cargo.toml rust-version - sha256 = "sha256-dxE7lmCFWlq0nl/wKcmYvpP9zqQbBitAQgZ1zx9Ooik="; + channel = "1.75"; # keep in sync with ./Cargo.toml rust-version + sha256 = "sha256-SXRtAuO4IqNOQq+nLbrsDFbVk+3aVA8NNpSZsKlVH/8="; }).defaultToolchain ] ++ common; };