diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml
index ca00651..f3e1160 100644
--- a/.github/workflows/rust.yml
+++ b/.github/workflows/rust.yml
@@ -16,7 +16,9 @@ jobs:
- uses: actions/checkout@v3
- name: Fetch library
run: |
- wget https://github.com/chdb-io/chdb/releases/latest/download/linux-x86_64-libchdb.tar.gz
+ #wget https://github.com/chdb-io/chdb/releases/latest/download/linux-x86_64-libchdb.tar.gz
+ #Fix libchdb version to v2.1.1 until libchdb v3 based chdb-rust refactor
+ wget https://github.com/chdb-io/chdb/releases/download/v2.1.1/linux-x86_64-libchdb.tar.gz
tar -xzf linux-x86_64-libchdb.tar.gz
sudo mv libchdb.so /usr/lib/libchdb.so
sudo ldconfig
diff --git a/.gitignore b/.gitignore
index 58c8d71..f5deb3b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,7 +2,7 @@
Cargo.lock
*.tar.gz
*.so
-*.h
+chdb.h
var
udf
*.parquet
diff --git a/Cargo.toml b/Cargo.toml
index bde8879..5ea76bd 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -9,3 +9,6 @@ thiserror = "1"
[build-dependencies]
bindgen = "0.70.1"
+
+[dev-dependencies]
+tempdir = "0.3.7"
\ No newline at end of file
diff --git a/README.md b/README.md
index f2e6fd2..a8b9ab5 100644
--- a/README.md
+++ b/README.md
@@ -3,21 +3,42 @@
[](https://github.com/chdb-io/chdb-rust/actions/workflows/rust.yml)
# chdb-rust
+
Experimental [chDB](https://github.com/chdb-io/chdb) FFI bindings for Rust
-### Status
+## Status
- Experimental, unstable, subject to changes
-- Requires [`libchdb`](https://github.com/chdb-io/chdb) on the system
+- Requires [`libchdb`](https://github.com/chdb-io/chdb) on the system. You can install the compatible version from
+ `install_libchdb.sh`
+
+## Usage
+
+### Install libchdb
+
+You can install it system-wide
+
+```bash
+./update_libchdb.sh --global
+```
+
+or use it in a local directory
+
+```bash
+./update_libchdb.sh --local
+```
+
+### Build
-#### Build binding
```bash
-./update_libchdb.sh
RUST_BACKTRACE=full cargo build --verbose
+
```
### Run tests
+
`cargo test`
### Examples
+
See `tests` directory.
diff --git a/build.rs b/build.rs
index fd76fcf..3e748b4 100644
--- a/build.rs
+++ b/build.rs
@@ -16,7 +16,7 @@ fn main() {
let bindings = bindgen::Builder::default()
// The input header we would like to generate
// bindings for.
- .header("chdb.h")
+ .header("wrapper.h")
// Tell cargo to invalidate the built crate whenever any of the
// included header files changed.
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
diff --git a/src/error.rs b/src/error.rs
index cf9023f..e1276a2 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -1,9 +1,12 @@
use std::ffi::NulError;
+use std::string::FromUtf8Error;
#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error("An unknown error has occurred")]
Unknown,
+ #[error("No result")]
+ NoResult,
#[error("Invalid data: {0}")]
InvalidData(String),
#[error("Invalid path")]
@@ -15,7 +18,9 @@ pub enum Error {
#[error("Insufficient dir permissions")]
InsufficientPermissions,
#[error("Non UTF-8 sequence: {0}")]
- NonUtf8Sequence(String),
+ NonUtf8Sequence(FromUtf8Error),
#[error("{0}")]
QueryError(String),
}
+
+pub type Result = std::result::Result;
diff --git a/src/lib.rs b/src/lib.rs
index 2c3e606..5ff5bf6 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -17,9 +17,10 @@ use std::ffi::{c_char, CString};
use crate::arg::Arg;
use crate::error::Error;
+use crate::error::Result;
use crate::query_result::QueryResult;
-pub fn execute(query: &str, query_args: Option<&[Arg]>) -> Result