Skip to content

Commit

Permalink
feat: upgrade rust client for 1.0 release (#33)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ShiKaiWi authored Mar 1, 2023
1 parent 8dd15f3 commit df92d4e
Show file tree
Hide file tree
Showing 9 changed files with 182 additions and 69 deletions.
55 changes: 39 additions & 16 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 2 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
[package]
name = "ceresdb-client-py"
version = "0.1.4"
version = "1.0.0"
authors = ["CeresDB Authors <[email protected]>"]
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ceresdb-client = "1.0"
pyo3 = { version = "0.16", features = ["extension-module", "abi3-py37"] }
pyo3-asyncio = { version = "0.16", features = ["attributes", "tokio-runtime"] }
tokio = { version = "1", features = ["sync"] }

[dependencies.ceresdb-client-rs]
git = "https://github.com/CeresDB/ceresdb-client-rs.git"
rev = "b9efb90e06c99f59e8580a8f8f56badd81b88aa2"

[lib]
crate-type = ["cdylib"]
name = "ceresdb_client"
Expand Down
4 changes: 2 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn main() {
// More details at https://github.com/alexcrichton/curl-rust/issues/279.
if let Some(path) = macos_link_search_path() {
println!("cargo:rustc-link-lib=clang_rt.osx");
println!("cargo:rustc-link-search={}", path);
println!("cargo:rustc-link-search={path}");
}
}
}
Expand All @@ -34,7 +34,7 @@ fn macos_link_search_path() -> Option<String> {
if line.contains("libraries: =") {
let path = line.split('=').nth(1)?;
if !path.is_empty() {
return Some(format!("{}/lib/darwin", path));
return Some(format!("{path}/lib/darwin"));
}
}
}
Expand Down
20 changes: 15 additions & 5 deletions ceresdb_client.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ class SqlQueryRequest:


class SqlQueryResponse:
def row_num(self) -> int: ...
def get_row(self, idx: int) -> Optional[Row]: ...
def num_rows(self) -> int: ...
def row_by_idx(self, idx: int) -> Optional[Row]: ...
def iter_rows(self) -> RowIter: ...
@property
def affected_rows(self) -> int: ...

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


class Column:
def name(self) -> str: ...
def value(self) -> Any: ...
def data_type(self) -> DataType: ...
def name(self) -> str: ...


class Row:
def column_by_idx(self, idx: int) -> Any: ...
def column_by_name(self, name: str) -> Any: ...
def column(self, name: str) -> Optional[Column]: ...
def column_by_idx(self, idx: int) -> Optional[Column]: ...
def num_cols(self) -> int: ...
def iter_columns(self) -> ColumnIter: ...


class ColumnIter:
def __iter__(self) -> Column: ...


class RowIter:
def __iter__(self) -> Row: ...


class Value:
Expand Down
13 changes: 10 additions & 3 deletions examples/read_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,22 @@ def sync_query(cli, ctx, req):
def process_query_resp(resp):
print(f"Raw resp is:\n{resp}\n")

print(f"Rows in the resp:")
for row_idx in range(0, resp.row_num()):
print(f"Access row by index in the resp:")
for row_idx in range(0, resp.num_rows()):
row_tokens = []
row = resp.get_row(row_idx)
row = resp.row_by_idx(row_idx)
for col_idx in range(0, row.num_cols()):
col = row.column_by_idx(col_idx)
row_tokens.append(f"{col.name()}:{col.value()}#{col.data_type()}")
print(f"row#{col_idx}: {','.join(row_tokens)}")

print(f"Access row by iter in the resp:")
for row in resp.iter_rows():
row_tokens = []
for col in row.iter_columns():
row_tokens.append(f"{col.name()}:{col.value()}#{col.data_type()}")
print(f"row: {','.join(row_tokens)}")


async def async_write(cli, ctx, req):
return await cli.write(ctx, req)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "ceresdb-client"
version = "0.1.4"
version = "1.0.0"
description = "The python client for ceresdb."
readme = "README.md"
requires-python = ">=3.7"
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nightly-2022-08-08
nightly-2023-02-02
6 changes: 3 additions & 3 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

use ceresdb_client_rs::{
use ceresdb_client::{
db_client::{Builder as RustBuilder, DbClient, Mode as RustMode},
RpcConfig as RustRpcConfig, RpcContext as RustRpcContext,
};
Expand Down Expand Up @@ -43,7 +43,7 @@ impl RpcContext {
}

pub fn __str__(&self) -> String {
format!("{:?}", self)
format!("{self:?}")
}
}

Expand All @@ -65,7 +65,7 @@ pub struct Client {
}

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

#[pymethods]
Expand Down
Loading

0 comments on commit df92d4e

Please sign in to comment.