Skip to content

Commit

Permalink
deserialize: impl DeserializeRow for Row
Browse files Browse the repository at this point in the history
This implementation is important for two reasons:
1. It enables using the upper layers of the old framework over the new
   one, which makes the transition smoother.
2. Some users (perhaps ORM users?) are going to need the dynamic
   capabilities that the previous framework offered: receiving rows
   consisting of arbitrary number of columns of arbitrary types.
   This is a perfect use case for Row.

Co-authored-by: Piotr Dulikowski <[email protected]>
  • Loading branch information
wprzytula and piodul committed Mar 24, 2024
1 parent 1160d91 commit e8e2189
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion scylla-cql/src/types/deserialize/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

use super::{value::DeserializeCql, FrameSlice};
use crate::frame::frame_errors::ParseError;
use crate::frame::response::result::ColumnSpec;
use crate::frame::response::result::CqlValue;
use crate::frame::response::result::{ColumnSpec, Row};

/// Represents a raw, unparsed column value.
#[non_exhaustive]
Expand Down Expand Up @@ -85,6 +86,26 @@ where
fn deserialize(row: ColumnIterator<'frame>) -> Result<Self, ParseError>;
}

impl<'frame> DeserializeRow<'frame> for Row {
#[inline]
fn type_check(_specs: &[ColumnSpec]) -> Result<(), ParseError> {
// CqlValues accept all types, no type checking needed
Ok(())
}

#[inline]
fn deserialize(mut row: ColumnIterator<'frame>) -> Result<Self, ParseError> {
let mut columns = Vec::with_capacity(row.size_hint().0);
while let Some(column) = row.next().transpose()? {
columns.push(<Option<CqlValue>>::deserialize(
&column.spec.typ,
column.slice,
)?);
}
Ok(Self { columns })
}
}

impl<'frame> DeserializeRow<'frame> for ColumnIterator<'frame> {
#[inline]
fn type_check(_specs: &[ColumnSpec]) -> Result<(), ParseError> {
Expand Down

0 comments on commit e8e2189

Please sign in to comment.