Skip to content

Commit

Permalink
Implement From<model::*> for Value (#317)
Browse files Browse the repository at this point in the history
Co-authored-by: Aljaž Mur Eržen <[email protected]>
  • Loading branch information
MrFoxPro and aljazerzen authored Apr 18, 2024
1 parent 0a6d2ea commit eeab4a5
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
50 changes: 49 additions & 1 deletion edgedb-protocol/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use bytes::Bytes;

use crate::codec::{NamedTupleShape, ObjectShape, ShapeElement};
use crate::common::Cardinality;
use crate::model::{BigInt, Decimal, Uuid, ConfigMemory, Range};
use crate::model::{BigInt, ConfigMemory, Decimal, Range, Uuid};
use crate::model::{LocalDatetime, LocalDate, LocalTime, Duration, Datetime};
use crate::model::{RelativeDuration, DateDuration, Json};
pub use crate::codec::EnumValue;
Expand Down Expand Up @@ -197,3 +197,51 @@ impl From<f64> for Value {
Value::Float64(num)
}
}

impl From<BigInt>for Value {
fn from(model: BigInt) -> Value {
Value::BigInt(model)
}
}

impl From<Decimal> for Value {
fn from(v: Decimal) -> Value {
Value::Decimal(v)
}
}

impl From<Uuid> for Value {
fn from(v: Uuid) -> Value {
Value::Uuid(v)
}
}

impl From<Json> for Value {
fn from(v: Json) -> Value {
Value::Json(v)
}
}

impl From<Duration> for Value {
fn from(v: Duration) -> Value {
Value::Duration(v)
}
}

impl From<Datetime> for Value {
fn from(v: Datetime) -> Value {
Value::Datetime(v)
}
}

impl From<LocalDate> for Value {
fn from(v: LocalDate) -> Value {
Value::LocalDate(v)
}
}

impl From<LocalDatetime> for Value {
fn from(v: LocalDatetime) -> Value {
Value::LocalDatetime(v)
}
}
13 changes: 13 additions & 0 deletions edgedb-tokio/tests/func/client.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use std::str::FromStr;

use edgedb_protocol::model::Uuid;
use edgedb_protocol::named_args;
use edgedb_protocol::value::{EnumValue, Value};
use edgedb_tokio::Client;
Expand Down Expand Up @@ -87,6 +90,16 @@ async fn simple() -> anyhow::Result<()> {
).await.unwrap();
assert_eq!(value.as_str(), "the answer to the ultimate question of life: 42");

// args for values
let uuid = "43299d0a-f993-4dcb-a8a2-50041bf5af79";
let value = client.query_required_single::<Uuid, _>(
"select <uuid>$my_uuid;",
&named_args! {
"my_uuid" => Uuid::from_str("43299d0a-f993-4dcb-a8a2-50041bf5af79").unwrap(),
}
).await.unwrap();
assert_eq!(value, Uuid::from_str(uuid).unwrap());

Ok(())
}

Expand Down

0 comments on commit eeab4a5

Please sign in to comment.