mirror of
https://github.com/hanzo-ds/rs.git
synced 2026-10-30 20:49:56 +00:00
Cut from the upstream v0.13.3 release tag (not HEAD) so this is a pure
rename with no behaviour change. v0.13.3 is what our consumers already
resolve to: insights/rust's Cargo.lock pins clickhouse 0.13.3 and its
manifest already declares `datastore` at 0.13.x.
The load-bearing change is the HTTP auth header rename. The Datastore
server reads only X-Datastore-User / X-Datastore-Key; the upstream names
return `401 Code: 194 Authentication failed`. Every un-renamed HTTP
client is therefore unable to authenticate at all — this is a
correctness fix, not branding.
- crate `clickhouse` -> `datastore`, `clickhouse-derive` -> `datastore-derive`;
versions preserved exactly (0.13.3 / 0.2.0).
- derive macro emits `datastore::Row` in lockstep, so downstream
`#[derive(Row)]` keeps resolving.
- User-Agent reports `datastore-rs/{version}`.
- test-harness env vars CLICKHOUSE_* -> DATASTORE_*; compose uses
ghcr.io/hanzoai/datastore with /etc/datastore-server config paths.
- doc links point at docs.hanzo.ai/datastore.
- `publish = false`: the `datastore` name on crates.io belongs to an
unrelated crate, so consume this by git tag, never by version range.
CHANGELOG is truncated to a fork notice rather than find-replaced —
rewriting upstream release history would manufacture changes Datastore
never shipped. References to upstream issues keep their numbers.
78 lines
1.8 KiB
Rust
78 lines
1.8 KiB
Rust
use std::time::UNIX_EPOCH;
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
use serde_repr::{Deserialize_repr, Serialize_repr};
|
|
|
|
use datastore::{error::Result, Client, Row};
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<()> {
|
|
let client = Client::default().with_url("http://localhost:8123");
|
|
|
|
client
|
|
.query("DROP TABLE IF EXISTS event_log")
|
|
.execute()
|
|
.await?;
|
|
|
|
client
|
|
.query(
|
|
"
|
|
CREATE TABLE event_log (
|
|
timestamp DateTime64(9),
|
|
message String,
|
|
level Enum8(
|
|
'Debug' = 1,
|
|
'Info' = 2,
|
|
'Warn' = 3,
|
|
'Error' = 4
|
|
)
|
|
)
|
|
ENGINE = MergeTree
|
|
ORDER BY timestamp",
|
|
)
|
|
.execute()
|
|
.await?;
|
|
|
|
#[derive(Debug, Serialize, Deserialize, Row)]
|
|
struct Event {
|
|
timestamp: u64,
|
|
message: String,
|
|
level: Level,
|
|
}
|
|
|
|
// How to define enums that map to `Enum8`/`Enum16`.
|
|
#[derive(Debug, Serialize_repr, Deserialize_repr)]
|
|
#[repr(u8)]
|
|
enum Level {
|
|
Debug = 1,
|
|
Info = 2,
|
|
Warn = 3,
|
|
Error = 4,
|
|
}
|
|
|
|
let mut insert = client.insert("event_log")?;
|
|
insert
|
|
.write(&Event {
|
|
timestamp: now(),
|
|
message: "one".into(),
|
|
level: Level::Info,
|
|
})
|
|
.await?;
|
|
insert.end().await?;
|
|
|
|
let events = client
|
|
.query("SELECT ?fields FROM event_log")
|
|
.fetch_all::<Event>()
|
|
.await?;
|
|
println!("{events:?}");
|
|
|
|
Ok(())
|
|
}
|
|
|
|
fn now() -> u64 {
|
|
UNIX_EPOCH
|
|
.elapsed()
|
|
.expect("invalid system time")
|
|
.as_nanos() as u64
|
|
}
|