Skip to content

Commit

Permalink
Merge pull request #56 from driftluo/ci
Browse files Browse the repository at this point in the history
bump to 0.5
  • Loading branch information
driftluo authored Feb 6, 2021
2 parents c174db9 + 5f79c76 commit 259c5f4
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 35 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "influx_db_client"
version = "0.4.5"
version = "0.5.0"
authors = ["piaoliu <[email protected]>"]
documentation = "https://docs.rs/influx_db_client/"
repository = "https://github.com/driftluo/InfluxDBClient-rs"
Expand Down
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);

Expand Down
38 changes: 34 additions & 4 deletions src/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ impl Point {
}

/// Add a tag and its value
pub fn add_tag<T: Into<String>>(mut self, tag: T, value: Value) -> Self {
self.tags.insert(tag.into(), value);
pub fn add_tag<T: Into<String>, F: Into<Value>>(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<T: Into<String>>(mut self, field: T, value: Value) -> Self {
self.fields.insert(field.into(), value);
pub fn add_field<T: Into<String>, F: Into<Value>>(mut self, field: T, value: F) -> Self {
self.fields.insert(field.into(), value.into());
self
}

Expand Down Expand Up @@ -207,3 +207,33 @@ macro_rules! point {
}
}};
}

impl From<String> 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<i64> for Value {
fn from(v: i64) -> Value {
Value::Integer(v)
}
}

impl From<f64> for Value {
fn from(v: f64) -> Value {
Value::Float(v)
}
}

impl From<bool> for Value {
fn from(v: bool) -> Value {
Value::Boolean(v)
}
}
36 changes: 17 additions & 19 deletions tests/client_test.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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]);

Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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();

Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit 259c5f4

Please sign in to comment.