From d6f7eee3558e44d2c4cd6df23b9e0d55764100ab Mon Sep 17 00:00:00 2001 From: driftluo Date: Sat, 6 Feb 2021 15:44:51 +0800 Subject: [PATCH 1/2] chore: change ci to github action --- .github/workflows/ci.yaml | 26 ++++++++++++++++++++++++++ src/keys.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 .github/workflows/ci.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..eb7fba7 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,26 @@ +name: Github Action + +on: + pull_request: # trigger on pull requests + push: + branches: + - master # trigger on push to master + - ci + +jobs: + test: + name: Test + runs-on: ubuntu-latest + strategy: + matrix: + include: + - rust: stable + steps: + - uses: actions/checkout@v2 + - name: Test + run: | + wget https://dl.influxdata.com/influxdb/releases/influxdb_1.8.0_amd64.deb + sudo dpkg -i influxdb_1.8.0_amd64.deb + sudo /usr/bin/influxd > $HOME/influx.log 2>&1 & + cargo test + cat $HOME/influx.log \ No newline at end of file diff --git a/src/keys.rs b/src/keys.rs index 4e1412a..9cb3160 100644 --- a/src/keys.rs +++ b/src/keys.rs @@ -207,3 +207,33 @@ macro_rules! point { } }}; } + +impl From for Value { + fn from(v: String) -> Value { + Value::String(v) + } +} + +impl From<&str> for Value { + fn from(v: &str) -> Value { + Value::String(v.to_string()) + } +} + +impl From for Value { + fn from(v: i64) -> Value { + Value::Integer(v) + } +} + +impl From for Value { + fn from(v: f64) -> Value { + Value::Float(v) + } +} + +impl From for Value { + fn from(v: bool) -> Value { + Value::Boolean(v) + } +} From 5f79c762c21904cb0da68ebf95820ef025c78de6 Mon Sep 17 00:00:00 2001 From: driftluo Date: Sat, 6 Feb 2021 16:04:28 +0800 Subject: [PATCH 2/2] chore: bump to 0.5 --- Cargo.toml | 2 +- README.md | 22 +++++++++++----------- src/keys.rs | 8 ++++---- tests/client_test.rs | 36 +++++++++++++++++------------------- 4 files changed, 33 insertions(+), 35 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 73a4932..3df39c6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "influx_db_client" -version = "0.4.5" +version = "0.5.0" authors = ["piaoliu <441594700@qq.com>"] documentation = "https://docs.rs/influx_db_client/" repository = "https://github.com/driftluo/InfluxDBClient-rs" diff --git a/README.md b/README.md index 6caceef..0c51dbd 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ This project has been able to run properly, PR is welcome. ``` [dependencies] -influx_db_client = "^0.4.0" +influx_db_client = "^0.5.0" ``` ### http @@ -35,18 +35,18 @@ fn main() { let client = Client::default().set_authentication("root", "root"); let point = point!("test1") - .add_field("foo", Value::String("bar".to_string())) - .add_field("integer", Value::Integer(11)) - .add_field("float", Value::Float(22.3)) - .add_field("'boolean'", Value::Boolean(false)); + .add_field("foo", "bar") + .add_field("integer", 11) + .add_field("float", 22.3) + .add_field("'boolean'", false); let point1 = Point::new("test1") - .add_tag("tags", Value::String(String::from("\\\"fda"))) - .add_tag("number", Value::Integer(12)) - .add_tag("float", Value::Float(12.6)) - .add_field("fd", Value::String("'3'".to_string())) - .add_field("quto", Value::String("\\\"fda".to_string())) - .add_field("quto1", Value::String("\"fda".to_string())); + .add_tag("tags", "\\\"fda") + .add_tag("number", 12) + .add_tag("float", 12.6) + .add_field("fd", "'3'") + .add_field("quto", "\\\"fda") + .add_field("quto1", "\"fda"); let points = points!(point1, point); diff --git a/src/keys.rs b/src/keys.rs index 9cb3160..932726e 100644 --- a/src/keys.rs +++ b/src/keys.rs @@ -42,14 +42,14 @@ impl Point { } /// Add a tag and its value - pub fn add_tag>(mut self, tag: T, value: Value) -> Self { - self.tags.insert(tag.into(), value); + pub fn add_tag, F: Into>(mut self, tag: T, value: F) -> Self { + self.tags.insert(tag.into(), value.into()); self } /// Add a field and its value - pub fn add_field>(mut self, field: T, value: Value) -> Self { - self.fields.insert(field.into(), value); + pub fn add_field, F: Into>(mut self, field: T, value: F) -> Self { + self.fields.insert(field.into(), value.into()); self } diff --git a/tests/client_test.rs b/tests/client_test.rs index d82ab2f..a0f2aed 100644 --- a/tests/client_test.rs +++ b/tests/client_test.rs @@ -1,6 +1,4 @@ -use influx_db_client::{ - point, points, reqwest::Url, Client, Point, Points, Precision, UdpClient, Value, -}; +use influx_db_client::{point, points, reqwest::Url, Client, Point, Points, Precision, UdpClient}; use std::fs::File; use std::io::Read; use std::thread::sleep; @@ -28,10 +26,10 @@ fn create_and_delete_measurement() { client.switch_database("test_create_and_delete_measurement"); client.create_database(client.get_db()).await.unwrap(); let point = Point::new("temporary") - .add_field("foo", Value::String("bar".to_string())) - .add_field("integer", Value::Integer(11)) - .add_field("float", Value::Float(22.3)) - .add_field("'boolean'", Value::Boolean(false)); + .add_field("foo", "bar") + .add_field("integer", 11) + .add_field("float", 22.3) + .add_field("'boolean'", false); client .write_point(point, Some(Precision::Seconds), None) @@ -50,16 +48,16 @@ fn use_points() { client.switch_database("test_use_points"); client.create_database(client.get_db()).await.unwrap(); let point = Point::new("test1") - .add_field("foo", Value::String("bar".to_string())) - .add_field("integer", Value::Integer(11)) - .add_field("float", Value::Float(22.3)) - .add_field("'boolean'", Value::Boolean(false)); + .add_field("foo", "bar") + .add_field("integer", 11) + .add_field("float", 22.3) + .add_field("'boolean'", false); let point1 = Point::new("test2") - .add_tag("tags", Value::String(String::from("'=213w"))) - .add_tag("number", Value::Integer(12)) - .add_tag("float", Value::Float(12.6)) - .add_field("fd", Value::String("'3'".to_string())); + .add_tag("tags", "'=213w") + .add_tag("number", 12) + .add_tag("float", 12.6) + .add_field("fd", "'3'".to_string()); let points = Points::create_new(vec![point1, point]); @@ -83,7 +81,7 @@ fn query() { let mut client = Client::default().set_authentication("root", "root"); client.switch_database(dbname); client.create_database(client.get_db()).await.unwrap(); - let point = Point::new("test3").add_field("foo", Value::String("bar".to_string())); + let point = Point::new("test3").add_field("foo", "bar"); let point1 = point.clone(); let point = point.add_timestamp(1_508_981_970); let point1 = point1.add_timestamp(1_508_982_026); @@ -102,7 +100,7 @@ fn use_macro() { let mut client = Client::default().set_authentication("root", "root"); client.switch_database("use_macro"); client.create_database(client.get_db()).await.unwrap(); - let point = point!("test4").add_field("foo", Value::String("bar".to_string())); + let point = point!("test4").add_field("foo", "bar"); let point1 = point.clone(); let point = point.add_timestamp(1_508_981_970); let point1 = point1.add_timestamp(1_508_982_026); @@ -123,7 +121,7 @@ fn use_udp() { udp.add_host("127.0.0.1:8090".parse().unwrap()); let mut client = Client::default().set_authentication("root", "root"); - let point = point!("test").add_field("foo", Value::String(String::from("bar"))); + let point = point!("test").add_field("foo", "bar"); udp.write_point(point).unwrap(); @@ -253,7 +251,7 @@ bind-address = "127.0.0.1:{rpc_port}" block_on(async { client.create_database(client.get_db()).await.unwrap(); - let point = point!("foo").add_field("foo", Value::String(String::from("bar"))); + let point = point!("foo").add_field("foo", "bar"); client.write_point(point, None, None).await.unwrap();