Skip to content
This repository was archived by the owner on Mar 12, 2026. It is now read-only.

Commit df92d4e

Browse files
authored
feat: upgrade rust client for 1.0 release (#33)
* feat: upgrade rust client for 1.0 release * feat: bump the rust version * chore: fix clippy warnings * refactor: provide iterator for rows and columns * chore: update pyi * chore: add iter_columns for Row
1 parent 8dd15f3 commit df92d4e

File tree

9 files changed

+182
-69
lines changed

9 files changed

+182
-69
lines changed

Cargo.lock

Lines changed: 39 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
11
[package]
22
name = "ceresdb-client-py"
3-
version = "0.1.4"
3+
version = "1.0.0"
44
authors = ["CeresDB Authors <ceresdbservice@gmail.com>"]
55
edition = "2021"
66

7-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
8-
97
[dependencies]
8+
ceresdb-client = "1.0"
109
pyo3 = { version = "0.16", features = ["extension-module", "abi3-py37"] }
1110
pyo3-asyncio = { version = "0.16", features = ["attributes", "tokio-runtime"] }
1211
tokio = { version = "1", features = ["sync"] }
1312

14-
[dependencies.ceresdb-client-rs]
15-
git = "https://github.com/CeresDB/ceresdb-client-rs.git"
16-
rev = "b9efb90e06c99f59e8580a8f8f56badd81b88aa2"
17-
1813
[lib]
1914
crate-type = ["cdylib"]
2015
name = "ceresdb_client"

build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fn main() {
1010
// More details at https://github.com/alexcrichton/curl-rust/issues/279.
1111
if let Some(path) = macos_link_search_path() {
1212
println!("cargo:rustc-link-lib=clang_rt.osx");
13-
println!("cargo:rustc-link-search={}", path);
13+
println!("cargo:rustc-link-search={path}");
1414
}
1515
}
1616
}
@@ -34,7 +34,7 @@ fn macos_link_search_path() -> Option<String> {
3434
if line.contains("libraries: =") {
3535
let path = line.split('=').nth(1)?;
3636
if !path.is_empty() {
37-
return Some(format!("{}/lib/darwin", path));
37+
return Some(format!("{path}/lib/darwin"));
3838
}
3939
}
4040
}

ceresdb_client.pyi

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ class SqlQueryRequest:
99

1010

1111
class SqlQueryResponse:
12-
def row_num(self) -> int: ...
13-
def get_row(self, idx: int) -> Optional[Row]: ...
12+
def num_rows(self) -> int: ...
13+
def row_by_idx(self, idx: int) -> Optional[Row]: ...
14+
def iter_rows(self) -> RowIter: ...
1415
@property
1516
def affected_rows(self) -> int: ...
1617

@@ -34,15 +35,24 @@ class DataType(enum.IntEnum):
3435

3536

3637
class Column:
38+
def name(self) -> str: ...
3739
def value(self) -> Any: ...
3840
def data_type(self) -> DataType: ...
39-
def name(self) -> str: ...
4041

4142

4243
class Row:
43-
def column_by_idx(self, idx: int) -> Any: ...
44-
def column_by_name(self, name: str) -> Any: ...
44+
def column(self, name: str) -> Optional[Column]: ...
45+
def column_by_idx(self, idx: int) -> Optional[Column]: ...
4546
def num_cols(self) -> int: ...
47+
def iter_columns(self) -> ColumnIter: ...
48+
49+
50+
class ColumnIter:
51+
def __iter__(self) -> Column: ...
52+
53+
54+
class RowIter:
55+
def __iter__(self) -> Row: ...
4656

4757

4858
class Value:

examples/read_write.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,22 @@ def sync_query(cli, ctx, req):
3737
def process_query_resp(resp):
3838
print(f"Raw resp is:\n{resp}\n")
3939

40-
print(f"Rows in the resp:")
41-
for row_idx in range(0, resp.row_num()):
40+
print(f"Access row by index in the resp:")
41+
for row_idx in range(0, resp.num_rows()):
4242
row_tokens = []
43-
row = resp.get_row(row_idx)
43+
row = resp.row_by_idx(row_idx)
4444
for col_idx in range(0, row.num_cols()):
4545
col = row.column_by_idx(col_idx)
4646
row_tokens.append(f"{col.name()}:{col.value()}#{col.data_type()}")
4747
print(f"row#{col_idx}: {','.join(row_tokens)}")
4848

49+
print(f"Access row by iter in the resp:")
50+
for row in resp.iter_rows():
51+
row_tokens = []
52+
for col in row.iter_columns():
53+
row_tokens.append(f"{col.name()}:{col.value()}#{col.data_type()}")
54+
print(f"row: {','.join(row_tokens)}")
55+
4956

5057
async def async_write(cli, ctx, req):
5158
return await cli.write(ctx, req)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "ceresdb-client"
3-
version = "0.1.4"
3+
version = "1.0.0"
44
description = "The python client for ceresdb."
55
readme = "README.md"
66
requires-python = ">=3.7"

rust-toolchain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
nightly-2022-08-08
1+
nightly-2023-02-02

src/client.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use std::{fmt::Debug, sync::Arc, time::Duration};
44

5-
use ceresdb_client_rs::{
5+
use ceresdb_client::{
66
db_client::{Builder as RustBuilder, DbClient, Mode as RustMode},
77
RpcConfig as RustRpcConfig, RpcContext as RustRpcContext,
88
};
@@ -43,7 +43,7 @@ impl RpcContext {
4343
}
4444

4545
pub fn __str__(&self) -> String {
46-
format!("{:?}", self)
46+
format!("{self:?}")
4747
}
4848
}
4949

@@ -65,7 +65,7 @@ pub struct Client {
6565
}
6666

6767
fn to_py_exception(err: impl Debug) -> PyErr {
68-
PyException::new_err(format!("{:?}", err))
68+
PyException::new_err(format!("{err:?}"))
6969
}
7070

7171
#[pymethods]

0 commit comments

Comments
 (0)