-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Value from Row #194
Comments
If you needed a convent use clickhouse_rs::{
errors::Result,
types::{Row, SqlType, ColumnType},
};
use serde_json::{Number, Value, Map};
fn row_to_json<C>(row: &Row<'_, C>) -> Result<Value>
where
C: ColumnType,
{
let mut result = Map::with_capacity(row.len());
for i in 0..row.len() {
let value = match row.sql_type(i)? {
SqlType::UInt32 => serde_json::Value::Number(Number::from(row.get::<u32, _>(i)?)),
SqlType::String | SqlType::FixedString(_) => serde_json::Value::String(row.get(i)?),
_ => todo!(),
};
result.insert(row.name(i)?.into(), value);
}
Ok(Value::Object(result))
} or if you needed iterator: fn row_to_iter<'a, C>(row: &'a Row<'_, C>) -> impl Iterator<Item = Result<Value>> + 'a
where
C: ColumnType,
{
(0..row.len()).map(|i| {
Ok(match row.sql_type(i)? {
SqlType::UInt32 => serde_json::Value::Number(Number::from(row.get::<u32, _>(i)?)),
SqlType::String | SqlType::FixedString(_) => serde_json::Value::String(row.get(i)?),
_ => todo!(),
})
})
} |
Yeah, I'm currently doing part of this I was just wondering if the lib already had this provided. Do you think it's worth it a PR with a |
What's the difference between enum Cell and clickhouse_rs::Value? Maybe it's better to export |
That's a good one too! The current only difference between my implementation of If I use Do you have plans to add a feature |
I have no plans to add |
Is it possible to get an Iterator from a
Row
?I'm currently converting back every value for my own
Value
so I can return them as json on my http server.The text was updated successfully, but these errors were encountered: