Skip to content

Commit

Permalink
fix: encode_tuples add LogicalType::Time
Browse files Browse the repository at this point in the history
  • Loading branch information
KKould committed Mar 25, 2024
1 parent fd24ab3 commit 540a546
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/bin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ fn encode_tuples<'a>(schema: &Schema, tuples: Vec<Tuple>) -> PgWireResult<QueryR
}
LogicalType::Date => encoder.encode_field(&value.date()),
LogicalType::DateTime => encoder.encode_field(&value.datetime()),
LogicalType::Time => encoder.encode_field(&value.time()),
LogicalType::Decimal(_, _) => todo!(),
_ => unreachable!(),
}?;
Expand Down
8 changes: 8 additions & 0 deletions src/types/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,14 @@ impl DataValue {
}
}

pub fn time(&self) -> Option<NaiveTime> {
if let DataValue::Time(Some(val)) = self {
NaiveTime::from_num_seconds_from_midnight_opt(*val, 0)
} else {
None
}
}

pub(crate) fn check_len(&self, logic_type: &LogicalType) -> Result<(), DatabaseError> {
let is_over_len = match (logic_type, self) {
(LogicalType::Varchar(Some(len)), DataValue::Utf8(Some(val))) => {
Expand Down

0 comments on commit 540a546

Please sign in to comment.