diff --git a/src/types/value.rs b/src/types/value.rs index 9b38b41..868330f 100644 --- a/src/types/value.rs +++ b/src/types/value.rs @@ -398,11 +398,11 @@ impl From for Value { } } -impl From> for Value { - fn from(v: Vec) -> Value { - Value::String(Arc::new(v)) - } -} +// impl From> for Value { +// fn from(v: Vec) -> Value { +// Value::String(Arc::new(v)) +// } +// } impl From<&[u8]> for Value { fn from(v: &[u8]) -> Value { @@ -419,6 +419,15 @@ impl From> for Value { } } +impl From> for Value { + fn from(v: Vec<&str>) -> Value { + Value::Array( + SqlType::String.into(), + Arc::new(v.into_iter().map(|v| v.into()).collect()) + ) + } +} + impl From for Value { fn from(v: Uuid) -> Value { let mut buffer = *v.as_bytes(); @@ -447,6 +456,24 @@ where } } +impl From> for Value { + fn from(v: Vec) -> Self { + Value::Array( + SqlType::DateTime(DateTimeType::DateTime32).into(), + Arc::new(v.into_iter().map(|a| a.into()).collect()), + ) + } +} + +impl From> for Value { + fn from(v: Vec) -> Self { + Value::Array( + SqlType::Date.into(), + Arc::new(v.into_iter().map(|a| a.into()).collect()), + ) + } +} + value_from! { bool: Bool, u8: UInt8, @@ -471,6 +498,7 @@ value_from! { } value_array_from! { + u8: UInt8, u16: UInt16, u32: UInt32, u64: UInt64, @@ -483,7 +511,9 @@ value_array_from! { i128: Int128, f32: Float32, - f64: Float64 + f64: Float64, + + bool: Bool } impl<'a> From<&'a str> for Value { @@ -835,6 +865,7 @@ mod test { let mut block = Block::with_capacity(5); block .push(row! { + u8: vec![1_u8, 2, 3], u16: vec![1_u16, 2, 3], u32: vec![1_u32, 2, 3], u64: vec![1_u64, 2, 3], @@ -848,6 +879,6 @@ mod test { .unwrap(); assert_eq!(block.row_count(), 1); - assert_eq!(block.column_count(), 9); + assert_eq!(block.column_count(), 10); } } diff --git a/tests/clickhouse.rs b/tests/clickhouse.rs index e72a1ad..fb2a596 100644 --- a/tests/clickhouse.rs +++ b/tests/clickhouse.rs @@ -1673,12 +1673,28 @@ async fn test_array() -> Result<(), Error> { .column("time64", vec![vec![date_time_value]]) .column("bln", vec![vec![true]]); + let mut block2 = Block::with_capacity(1); + for _i in 0..1 { + block2.push(row! { + u8:vec![31_u8], + u32:vec![42_u32], + f64:vec![42_f64], + text1:vec!["A"], + text2:vec!["B".to_string()], + date:vec![date_value], + time:vec![date_time_value], + time64:vec![date_time_value], + bln:vec![true], + })?; + } + let pool = Pool::new(database_url()); let mut c = pool.get_handle().await?; c.execute("DROP TABLE IF EXISTS clickhouse_array").await?; c.execute(ddl).await?; c.insert("clickhouse_array", block).await?; + c.insert("clickhouse_array", block2).await?; let block = c.query(query).fetch_all().await?; let u8_vec: Vec = block.get(0, "u8")?; @@ -1691,7 +1707,7 @@ async fn test_array() -> Result<(), Error> { let time64_vec: Vec> = block.get(0, "time64")?; let bln_vec: Vec = block.get(0, "bln")?; - assert_eq!(1, block.row_count()); + assert_eq!(2, block.row_count()); assert_eq!(vec![41_u8], u8_vec); assert_eq!(vec![42_u32], u32_vec); assert_eq!(vec![42_f64], f64_vec);