Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 0 additions & 78 deletions Handover.md

This file was deleted.

22 changes: 15 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ This client uses https://crates.io/crates/clickhouse as a dependency.

## Install Proton

Please install Proton as a standalone server or via Docker. Make sure port 8123 is exposed for `pront-rust-client` to connect and run SQL.

### As a single binary

On Linux or Mac, you can install it via `curl https://install.timeplus.com | sh`
Expand All @@ -27,11 +29,10 @@ In a separate terminal, connect to the server via `proton client` (Note: If you
### As a Docker container

```bash
docker run -d --pull always --name proton ghcr.io/timeplus-io/proton:latest
docker run -d --pull always --name proton -p 8123:8123 -p 8463:8463 ghcr.io/timeplus-io/proton:latest
```

Proton is automatically started. Open the terminal of the container, and run `proton client`

Proton is automatically started with port 8123 and 8463 exposed. Open the terminal of the container, and run `proton client`

For detailed usage and more information, check out the documentation: https://docs.timeplus.com/proton

Expand Down Expand Up @@ -77,21 +78,28 @@ const FN_NAME: &str = "[prepare]:";

#[tokio::main]
async fn main() -> Result<()> {
println!("{} Start", FN_NAME);
println!("{}Start", FN_NAME);

println!("{}Build client", FN_NAME);
let client = ProtonClient::new("http://localhost:8123");

println!("{} Create stream if not exists", FN_NAME);
println!("{}Create stream if not exists", FN_NAME);
create_stream(&client)
.await
.expect("[main]: Failed to create Stream");

println!("{} Stop", FN_NAME);
println!("{}Stop", FN_NAME);
Ok(())
}
}

pub async fn create_stream(client: &ProtonClient) -> Result<()> {
client
.execute_query("CREATE STREAM IF NOT EXISTS test_stream(no uint32, name string) ORDER BY no")
.await
}
```

Check more examples [here](examples).

## What's next?

Expand Down
30 changes: 17 additions & 13 deletions examples/README_EXAMPLES.md → examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

## Install Proton

Please install Proton as a standalone server or via Docker. Make sure port 8123 is exposed for `pront-rust-client` to connect and run SQL.

### As a single binary

On Linux or Mac, you can install it via `curl https://install.timeplus.com | sh`
Expand All @@ -18,10 +20,10 @@ In a separate terminal, connect to the server via `proton client` (Note: If you
### As a Docker container

```bash
docker run -d --pull always --name proton ghcr.io/timeplus-io/proton:latest
docker run -d --pull always --name proton -p 8123:8123 -p 8463:8463 ghcr.io/timeplus-io/proton:latest
```

Proton is automatically started. Open the terminal of the container, and run `proton client`
Proton is automatically started with port 8123 and 8463 exposed. Open the terminal of the container, and run `proton client`


For detailed usage and more information, check out the documentation: https://docs.timeplus.com/proton
Expand Down Expand Up @@ -58,7 +60,7 @@ const FN_NAME: &str = "[prepare]:";
async fn main() -> Result<()> {
println!("{} Start", FN_NAME);

println!("{}Build client", FN_NAME);
println!("{} Build client", FN_NAME);
let client = ProtonClient::new("http://localhost:8123");

println!("{} Create stream if not exists", FN_NAME);
Expand All @@ -74,28 +76,30 @@ async fn main() -> Result<()> {

## Run the client code example

In the root folder of `protno-rust-client`

1) Create a stream and insert some data

```
cargo run --bin prepare
cargo run --example prepare
```

Expected output

```
[prepare]: Start
[prepare]:Start
[prepare]:Build client
[prepare]: Create stream if not exists
[prepare]:Create stream if not exists
[prepare]:Insert data
[prepare]:Count inserted data
[prepare]:Inserted data: 1000
[prepare]: Stop
[prepare]:Stop
```

2) Stream some data (fetch) and load all data at once (fetch_all)

```
cargo run --bin main
cargo run --example query
```

Expected output
Expand All @@ -110,21 +114,21 @@ MyRow { no: 503, name: "foo" }
MyRow { no: 504, name: "foo" }
[main]:Fetch all data
[MyRowOwned { no: 500, name: "foo" }, MyRowOwned { no: 501, name: "foo" }, MyRowOwned { no: 502, name: "foo" }, MyRowOwned { no: 503, name: "foo" }, MyRowOwned { no: 504, name: "foo" }]
[main]: Stop
[main]:Stop
```

3) Cleanup and delete stream


```
cargo run --bin cleanup
cargo run --example remove
```

Expected output

```
[prepare]: Start
[prepare]:Start
[prepare]:Build client
[prepare]: Delete Stream
[prepare]: Stop
[prepare]:Delete Stream
[prepare]:Stop
```
12 changes: 6 additions & 6 deletions examples/prepare/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ impl<'a> MyRow<'a> {

#[tokio::main]
async fn main() -> Result<()> {
println!("{} Start", FN_NAME);
println!("{}Start", FN_NAME);

println!("{}Build client", FN_NAME);
let client = ProtonClient::new("http://localhost:8123");

println!("{} Create stream if not exists", FN_NAME);
println!("{}Create stream if not exists", FN_NAME);
create_stream(&client)
.await
.expect("[main]: Failed to create Stream");
Expand All @@ -39,19 +39,19 @@ async fn main() -> Result<()> {

println!("{}Inserted data: {}", FN_NAME, count);

println!("{} Stop", FN_NAME);
println!("{}Stop", FN_NAME);
Ok(())
}

pub async fn create_stream(client: &ProtonClient) -> Result<()> {
client
.execute_query("CREATE STREAM IF NOT EXISTS some(no uint32, name string) ORDER BY no")
.execute_query("CREATE STREAM IF NOT EXISTS test_stream(no uint32, name string) ORDER BY no")
.await
}

pub async fn insert(client: &ProtonClient) -> Result<()> {
let mut insert = client
.insert("some")
.insert("test_stream")
.await
.expect("[main/insert]: Failed to build inserter for table some");

Expand All @@ -70,7 +70,7 @@ pub async fn insert(client: &ProtonClient) -> Result<()> {
pub async fn select_count(client: &ProtonClient) -> Result<u64> {
let count = client
.clone()
.fetch_one("select count() from table(some)")
.fetch_one("select count() from table(test_stream)")
.await
.expect("[main/select_count]: Failed to fetch count()");

Expand Down
6 changes: 3 additions & 3 deletions examples/query/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ async fn main() -> Result<()> {
.await
.expect("[main/fetch_all]: Failed to fetch data");

println!("{} Stop", FN_NAME);
println!("{}Stop", FN_NAME);
Ok(())
}

pub async fn fetch(client: &ProtonClient) -> clickhouse::error::Result<()> {
let mut cursor = client
.fetch::<MyRow<'_>>("SELECT ?fields from table(some) WHERE no BETWEEN 500 AND 504")
.fetch::<MyRow<'_>>("SELECT ?fields from test_stream WHERE no BETWEEN 500 AND 504")
.await
.expect("[main/fetch]: Failed to fetch data");

Expand All @@ -69,7 +69,7 @@ pub async fn fetch(client: &ProtonClient) -> clickhouse::error::Result<()> {

pub async fn fetch_all(client: &ProtonClient) -> clickhouse::error::Result<()> {
let vec = client
.fetch_all::<MyRowOwned>("SELECT ?fields from table(some) WHERE no BETWEEN 500 AND 504")
.fetch_all::<MyRowOwned>("SELECT ?fields from test_stream WHERE no BETWEEN 500 AND 504")
.await
.expect("[main/fetch_all]: Failed to fetch all");

Expand Down
8 changes: 4 additions & 4 deletions examples/remove/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ const FN_NAME: &str = "[prepare]:";

#[tokio::main]
async fn main() -> Result<()> {
println!("{} Start", FN_NAME);
println!("{}Start", FN_NAME);

println!("{}Build client", FN_NAME);
let client = ProtonClient::new("http://localhost:8123");

println!("{} Delete Stream", FN_NAME);
println!("{}Delete Stream", FN_NAME);
delete_stream(&client)
.await
.expect("[main]: Failed to delete Stream");

println!("{} Stop", FN_NAME);
println!("{}Stop", FN_NAME);

Ok(())
}

pub async fn delete_stream(client: &ProtonClient) -> Result<()> {
// Drop a stream
// https://docs.timeplus.com/proton-drop-stream
client.execute_query("DROP STREAM some").await
client.execute_query("DROP STREAM IF EXISTS test_stream").await
}
8 changes: 4 additions & 4 deletions src/lib/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl ProtonClient {
/// let client = ProtonClient::new("http://localhost:8123");
///
/// let mut cursor = client
/// .fetch::<MyRow<'_>>("SELECT ?fields from table(some) WHERE no BETWEEN 500 AND 504")
/// .fetch::<MyRow<'_>>("SELECT ?fields from table(test_stream) WHERE no BETWEEN 500 AND 504")
/// .await
/// .expect("[main/fetch]: Failed to fetch data");
///
Expand Down Expand Up @@ -64,7 +64,7 @@ impl ProtonClient {
///
/// let client = ProtonClient::new("http://localhost:8123");
///
/// let query = "SELECT ?fields FROM some WHERE no BETWEEN 0 AND 1";
/// let query = "SELECT ?fields FROM test_stream WHERE no BETWEEN 0 AND 1";
/// let data = client.fetch_all::<MyRow>(query).await.unwrap();
///
/// println!("Received {} records", data.len());
Expand Down Expand Up @@ -100,7 +100,7 @@ impl ProtonClient {
/// async fn example() -> Result<()> {
///
/// let client = ProtonClient::new("http://localhost:8123");
/// let query = "select count() from table(table_name)";
/// let query = "select count() from table(test_stream)";
/// let item = client.fetch_one::<u64>(query).await.unwrap();
///
/// println!("Single result: {:#?}", item);
Expand Down Expand Up @@ -143,7 +143,7 @@ impl ProtonClient {
///
/// let client = ProtonClient::new("http://localhost:8123");
/// let item_id = 42;
/// let query = "SELECT ?fields FROM some WHERE no = 42";
/// let query = "SELECT ?fields FROM test_stream WHERE no = 42";
/// let item = client.fetch_optional::<MyRow>(query).await.unwrap();
///
/// match item {
Expand Down
6 changes: 3 additions & 3 deletions src/lib/getters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl ProtonClient {
///
/// async fn example() -> Result<()> {
///
/// let client = ProtonClient::new("https://api.proton.com");
/// let client = ProtonClient::new("http://localhost:8123");
///
/// let url = client.client().await;
///
Expand All @@ -37,11 +37,11 @@ impl ProtonClient {
///
/// async fn example() -> Result<()> {
///
/// let client = ProtonClient::new("https://api.proton.com");
/// let client = ProtonClient::new("http://localhost:8123");
///
/// let url = client.url().await;
///
/// assert_eq!(url, "https://api.proton.com");
/// assert_eq!(url, "http://localhost:8123");
///
/// Ok(())
/// }
Expand Down
Loading