Files
zeekay 86788566d1 datastore: rebrand the Rust client and speak the Datastore wire protocol
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.
2026-07-26 11:30:32 -07:00

83 lines
1.9 KiB
Rust

#![cfg(feature = "uuid")]
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use datastore::Row;
#[tokio::test]
async fn smoke() {
let client = prepare_database!();
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Row)]
struct MyRow {
#[serde(with = "datastore::serde::uuid")]
uuid: Uuid,
#[serde(with = "datastore::serde::uuid::option")]
uuid_opt: Option<Uuid>,
}
client
.query(
"
CREATE TABLE test(
uuid UUID,
uuid_opt Nullable(UUID)
) ENGINE = MergeTree ORDER BY uuid
",
)
.execute()
.await
.unwrap();
let uuid = Uuid::new_v4();
println!("uuid: {uuid}");
let original_row = MyRow {
uuid,
uuid_opt: Some(uuid),
};
let mut insert = client.insert("test").unwrap();
insert.write(&original_row).await.unwrap();
insert.end().await.unwrap();
let (row, row_uuid_str) = client
.query("SELECT ?fields, toString(uuid) FROM test")
.fetch_one::<(MyRow, String)>()
.await
.unwrap();
assert_eq!(row, original_row);
assert_eq!(row_uuid_str, original_row.uuid.to_string());
}
#[tokio::test]
async fn human_readable_smoke() {
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Row)]
struct OursRow {
#[serde(with = "datastore::serde::uuid")]
uuid: Uuid,
}
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, Row)]
struct TheirsRow {
uuid: Uuid,
}
let uuid = Uuid::new_v4();
let row = OursRow { uuid };
let row2 = TheirsRow { uuid };
let s1 = serde_json::to_string(&row).unwrap();
let s2 = serde_json::to_string(&row2).unwrap();
assert_eq!(s1, s2);
let new_row2: TheirsRow = serde_json::from_str(&s2).unwrap();
assert_eq!(new_row2, row2);
}