Skip to content
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

fix: implement DecodeScalar for Bytes #337

Merged
merged 5 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions edgedb-protocol/src/serialization/decode/queryable/scalars.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use bytes::Bytes;

use crate::queryable::DescriptorMismatch;
use crate::queryable::{Decoder, DescriptorContext, Queryable};

Expand Down Expand Up @@ -56,6 +58,15 @@ impl DecodeScalar for String {
}
}

impl DecodeScalar for Bytes {
fn uuid() -> Uuid {
codec::STD_BYTES
}
fn typename() -> &'static str {
"std::bytes"
}
}

impl DecodeScalar for Json {
fn uuid() -> Uuid {
codec::STD_JSON
Expand Down
4 changes: 1 addition & 3 deletions edgedb-protocol/src/value.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/*!
Contains the [Value] enum.
*/
use bytes::Bytes;

pub use crate::codec::EnumValue;
use crate::codec::{NamedTupleShape, ObjectShape, ShapeElement};
use crate::common::Cardinality;
Expand All @@ -15,7 +13,7 @@ pub enum Value {
Nothing,
Uuid(Uuid),
Str(String),
Bytes(Bytes),
Bytes(bytes::Bytes),
Int16(i16),
Int32(i32),
Int64(i64),
Expand Down
19 changes: 19 additions & 0 deletions edgedb-tokio/tests/func/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,22 @@ async fn big_num() -> anyhow::Result<()> {

Ok(())
}

#[tokio::test]
async fn bytes() -> anyhow::Result<()> {
let client = Client::new(&SERVER.config);
client.ensure_connected().await?;

#[derive(Queryable)]
struct MyResult {
data: bytes::Bytes,
}

let res = client
.query_required_single::<MyResult, _>("select { data := b'101' } limit 1", &())
.await
.unwrap();

assert_eq!(res.data, b"101"[..]);
Ok(())
}
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
buildInputs = [
(fenix_pkgs.fromToolchainFile {
file = ./rust-toolchain.toml;
sha256 = "sha256-6eN/GKzjVSjEhGO9FhWObkRFaE1Jf+uqMSdQnb8lcB4=";
sha256 = "sha256-3jVIIf5XPnUU1CRaTyAiO0XHVbJl12MSx3eucTXCjtE=";
})
] ++ common;
};
Expand Down
Loading