From cda64f8fbb4973ad1060130c68acf9c3e2622d1a Mon Sep 17 00:00:00 2001 From: OMGeeky Date: Sat, 3 Jun 2023 12:51:49 +0200 Subject: [PATCH] better value-type matching in convert_bigquery_params.rs --- .gitignore | 1 + Cargo.toml | 2 +- .../param_conversion/convert_bigquery_params.rs | 17 +++++++++-------- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 117278f..dbc19eb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /target /.idea /auth +/Cargo.lock diff --git a/Cargo.toml b/Cargo.toml index 0ef7f22..7e64d8a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "google_bigquery_v2" -version = "0.2.2" +version = "0.2.3" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/data/param_conversion/convert_bigquery_params.rs b/src/data/param_conversion/convert_bigquery_params.rs index 8fec3ad..b8f0b34 100644 --- a/src/data/param_conversion/convert_bigquery_params.rs +++ b/src/data/param_conversion/convert_bigquery_params.rs @@ -1,7 +1,6 @@ use std::fmt::Debug; use chrono::{NaiveDateTime, Utc}; -use crate::prelude::*; use serde_json::{value, Value}; use crate::prelude::*; @@ -138,13 +137,15 @@ pub fn convert_value_to_string(value: Value) -> Result { trace!("ConvertValueToBigqueryParamValue::convert_value_type_to_bigquery_type: String"); Ok(value::from_value(value)?) } else { - warn!("Unknown type: {:?}", value); - if value == Value::Null { - return Err("Value is Null".into()); + match value { + Value::Null => Err("Value is Null".into()), + Value::Number(num) => Ok(num.to_string()), + Value::String(s) => Ok(s), + _ => { + warn!("Unknown type: {:?}", value); + //TODO: check if this is correct with for example 'DATETIME' values + Ok(value.to_string()) + } } - //TODO: check if this is correct with for example 'DATETIME' values - // Err(format!("Unknown type: {:?}", value).into()) - let string = value.to_string(); - Ok(string) }; }