Skip to content

Commit

Permalink
Add 'ColumnType::Timeuuid' support for the prepared statements
Browse files Browse the repository at this point in the history
  • Loading branch information
vponomaryov committed Jun 28, 2024
1 parent d3c6850 commit f3ac299
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use rune::{Any, Value};
use rust_embed::RustEmbed;
use scylla::_macro_internal::ColumnType;
use scylla::frame::response::result::CqlValue;
use scylla::frame::value::CqlTimeuuid;
use scylla::prepared_statement::PreparedStatement;
use scylla::transport::errors::{DbError, NewSessionError, QueryError};
use scylla::transport::session::PoolSize;
Expand Down Expand Up @@ -197,6 +198,7 @@ pub enum CassErrorKind {
ValueOutOfRange(String, ColumnType),
InvalidNumberOfQueryParams,
InvalidQueryParamsObject(TypeInfo),
WrongDataStructure(String),
Prepare(String, QueryError),
Overloaded(QueryInfo, QueryError),
QueryExecution(QueryInfo, QueryError),
Expand Down Expand Up @@ -233,6 +235,9 @@ impl CassError {
CassErrorKind::InvalidQueryParamsObject(t) => {
write!(buf, "Value of type {t} cannot by used as query parameters; expected a list or object")
}
CassErrorKind::WrongDataStructure(s) => {
write!(buf, "Wrong data structure: {s}")
}
CassErrorKind::Prepare(q, e) => {
write!(buf, "Failed to prepare query \"{q}\": {e}")
}
Expand Down Expand Up @@ -584,6 +589,29 @@ mod bind {
(Value::Float(v), ColumnType::Float) => Ok(CqlValue::Float(*v as f32)),
(Value::Float(v), ColumnType::Double) => Ok(CqlValue::Double(*v)),

(Value::StaticString(v), ColumnType::Timeuuid) => {
let timeuuid = CqlTimeuuid::from_str(v);
match timeuuid {
Ok(timeuuid) => Ok(CqlValue::Timeuuid(timeuuid)),
Err(e) => {
Err(CassError(CassErrorKind::WrongDataStructure(
format!("Failed to parse '{}' StaticString as Timeuuid: {}", v.as_str(), e),
)))
}
}
}
(Value::String(v), ColumnType::Timeuuid) => {
let timeuuid_str = v.borrow_ref().unwrap();
let timeuuid = CqlTimeuuid::from_str(timeuuid_str.as_str());
match timeuuid {
Ok(timeuuid) => Ok(CqlValue::Timeuuid(timeuuid)),
Err(e) => {
Err(CassError(CassErrorKind::WrongDataStructure(
format!("Failed to parse '{}' String as Timeuuid: {}", timeuuid_str.as_str(), e),
)))
}
}
}
(Value::StaticString(v), ColumnType::Text | ColumnType::Ascii) => {
Ok(CqlValue::Text(v.as_str().to_string()))
}
Expand Down

0 comments on commit f3ac299

Please sign in to comment.