Skip to content
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
26 changes: 13 additions & 13 deletions src/base/value.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{api_bail, api_error};

use bytes::Bytes;
use super::schema::*;
use anyhow::Result;
use base64::prelude::*;
Expand Down Expand Up @@ -73,7 +73,7 @@ impl<'de> Deserialize<'de> for RangeValue {
/// Value of key.
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum KeyValue {
Bytes(Arc<[u8]>),
Bytes(Bytes),
Str(Arc<str>),
Bool(bool),
Int64(i64),
Expand All @@ -83,15 +83,15 @@ pub enum KeyValue {
Struct(Vec<KeyValue>),
}

impl From<Arc<[u8]>> for KeyValue {
fn from(value: Arc<[u8]>) -> Self {
impl From<Bytes> for KeyValue {
fn from(value: Bytes) -> Self {
KeyValue::Bytes(value)
}
}

impl From<Vec<u8>> for KeyValue {
fn from(value: Vec<u8>) -> Self {
KeyValue::Bytes(Arc::from(value))
KeyValue::Bytes(Bytes::from(value))
}
}

Expand Down Expand Up @@ -197,7 +197,7 @@ impl KeyValue {
.ok_or_else(|| api_error!("Key parts less than expected"))?;
match basic_type {
BasicValueType::Bytes { .. } => {
KeyValue::Bytes(Arc::from(BASE64_STANDARD.decode(v)?))
KeyValue::Bytes(Bytes::from(BASE64_STANDARD.decode(v)?))
}
BasicValueType::Str { .. } => KeyValue::Str(Arc::from(v)),
BasicValueType::Bool => KeyValue::Bool(v.parse()?),
Expand Down Expand Up @@ -275,7 +275,7 @@ impl KeyValue {
}
}

pub fn bytes_value(&self) -> Result<&Arc<[u8]>> {
pub fn bytes_value(&self) -> Result<&Bytes> {
match self {
KeyValue::Bytes(v) => Ok(v),
_ => anyhow::bail!("expected bytes value, but got {}", self.kind_str()),
Expand Down Expand Up @@ -342,7 +342,7 @@ impl KeyValue {

#[derive(Debug, Clone)]
pub enum BasicValue {
Bytes(Arc<[u8]>),
Bytes(Bytes),
Str(Arc<str>),
Bool(bool),
Int64(i64),
Expand All @@ -358,15 +358,15 @@ pub enum BasicValue {
Vector(Arc<[BasicValue]>),
}

impl From<Arc<[u8]>> for BasicValue {
fn from(value: Arc<[u8]>) -> Self {
impl From<Bytes> for BasicValue {
fn from(value: Bytes) -> Self {
BasicValue::Bytes(value)
}
}

impl From<Vec<u8>> for BasicValue {
fn from(value: Vec<u8>) -> Self {
BasicValue::Bytes(Arc::from(value))
BasicValue::Bytes(Bytes::from(value))
}
}

Expand Down Expand Up @@ -674,7 +674,7 @@ impl<VS> Value<VS> {
}
}

pub fn as_bytes(&self) -> Result<&Arc<[u8]>> {
pub fn as_bytes(&self) -> Result<&Bytes> {
match self {
Value::Basic(BasicValue::Bytes(v)) => Ok(v),
_ => anyhow::bail!("expected bytes value, but got {}", self.kind()),
Expand Down Expand Up @@ -870,7 +870,7 @@ impl BasicValue {
pub fn from_json(value: serde_json::Value, schema: &BasicValueType) -> Result<Self> {
let result = match (value, schema) {
(serde_json::Value::String(v), BasicValueType::Bytes { .. }) => {
BasicValue::Bytes(Arc::from(BASE64_STANDARD.decode(v)?))
BasicValue::Bytes(Bytes::from(BASE64_STANDARD.decode(v)?))
}
(serde_json::Value::String(v), BasicValueType::Str { .. }) => {
BasicValue::Str(Arc::from(v))
Expand Down
4 changes: 1 addition & 3 deletions src/ops/storages/neo4j.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,7 @@ fn mapped_field_values_to_bolt<'a>(

fn basic_value_to_bolt(value: &BasicValue, schema: &BasicValueType) -> Result<BoltType> {
let bolt_value = match value {
BasicValue::Bytes(v) => {
BoltType::Bytes(neo4rs::BoltBytes::new(bytes::Bytes::from_owner(v.clone())))
}
BasicValue::Bytes(v) => BoltType::Bytes(neo4rs::BoltBytes::new(v.clone())),
BasicValue::Str(v) => BoltType::String(neo4rs::BoltString::new(v)),
BasicValue::Bool(v) => BoltType::Boolean(neo4rs::BoltBoolean::new(*v)),
BasicValue::Int64(v) => BoltType::Integer(neo4rs::BoltInteger::new(*v)),
Expand Down
6 changes: 4 additions & 2 deletions src/ops/storages/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use sqlx::postgres::PgRow;
use sqlx::{PgPool, Row};
use std::ops::Bound;
use uuid::Uuid;
use bytes::Bytes;

#[derive(Debug, Deserialize)]
pub struct Spec {
Expand Down Expand Up @@ -175,7 +176,7 @@ fn from_pg_value(row: &PgRow, field_idx: usize, typ: &ValueType) -> Result<Value
let basic_value = match basic_type {
BasicValueType::Bytes => row
.try_get::<Option<Vec<u8>>, _>(field_idx)?
.map(|v| BasicValue::Bytes(Arc::from(v))),
.map(|v| BasicValue::Bytes(Bytes::from(v))),
BasicValueType::Str => row
.try_get::<Option<String>, _>(field_idx)?
.map(|v| BasicValue::Str(Arc::from(v))),
Expand Down Expand Up @@ -855,7 +856,8 @@ impl setup::ResourceSetupStatusCheck for SetupStatusCheck {
TableUpsertionAction::Create { keys, values } => {
let mut fields = (keys
.iter()
.map(|(k, v)| format!("{} {} NOT NULL", k, to_column_type_sql(v))))
.map(|(k, v)| format!("{} {} NOT NULL", k, to_column_type_sql(v)))
)
.chain(
values
.iter()
Expand Down
5 changes: 3 additions & 2 deletions src/py/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use serde::de::DeserializeOwned;
use serde::Serialize;
use std::collections::BTreeMap;
use std::ops::Deref;
use std::sync::Arc;
use std::sync::Arc;
use bytes::Bytes;

use super::IntoPyResult;
use crate::base::{schema, value};
Expand Down Expand Up @@ -123,7 +124,7 @@ fn basic_value_from_py_object<'py>(
) -> PyResult<value::BasicValue> {
let result = match typ {
schema::BasicValueType::Bytes => {
value::BasicValue::Bytes(Arc::from(v.extract::<Vec<u8>>()?))
value::BasicValue::Bytes(Bytes::from(v.extract::<Vec<u8>>()?))
}
schema::BasicValueType::Str => value::BasicValue::Str(Arc::from(v.extract::<String>()?)),
schema::BasicValueType::Bool => value::BasicValue::Bool(v.extract::<bool>()?),
Expand Down