# DuckDB Server [![Crates.io](https://img.shields.io/crates/v/duckdb-server.svg)](https://crates.io/crates/duckdb-server) A Rust-based server that runs a local DuckDB instance and supports queries over HTTP/HTTPS, returning data in [Apache Arrow](https://arrow.apache.org/) format. _Note:_ This package provides a local DuckDB server. To instead use DuckDB-WASM in the browser, use the `wasmConnector` in the [`mosaic-core`](https://github.com/uwdata/mosaic/tree/main/packages/mosaic/mosaic-core) package. ## Usage Install the server with Cargo or [Cargo B(inary)Install](https://github.com/cargo-bins/cargo-binstall). ```sh cargo install duckdb-server # or cargo binstall duckdb-server ``` Then run the server with ```sh duckdb-server ``` You can disable or customize logging with the `RUST_LOG` environment variable. ```sh env RUST_LOG="" duckdb-server ``` The server can reuse existing sockets with `listenfd`. ```sh systemfd --no-pid -s http::3000 -- duckdb-server ``` To set up shared HTTPS/HTTP/2 certificates, run from the repository root: ```sh pnpm mkcert ``` Install native mkcert on `PATH` first. The server checks the working directory, then the shared user directory for `localhost.pem` and `localhost-key.pem`. See the [server guide](../README.md) for paths, local overrides, and renewal. With certificates present, the server accepts both HTTP and HTTPS on the same port. ## API The server supports queries via HTTP GET and POST. The GET endpoint is useful for debugging. For example, you can query it with [this url](). Each endpoint takes a JSON object with a command in the `type`. The server supports the following commands. ### `exec` Executes the SQL query in the `sql` field. ### `arrow` Executes the SQL query in the `sql` field and returns the result in Apache Arrow format. ## Developers ### Build Build the release binary with ```sh cargo build --release ``` ### Develop To run the server and restart it when the code changes, install `cargo-watch` and `systemfd` with ```sh cargo install cargo-watch systemfd ``` Then run the server with ```sh systemfd --no-pid -s https::3000 -- cargo watch -x run ``` Or just use (but this won't restart when the code changes) ```sh cargo run ``` Before sending a pull request, run the tests with ```sh cargo test cargo clippy cargo fmt ``` Run the benchmarks with ```sh cargo bench ``` ### Update Dependencies Update the lockfile with `cargo update` and look for outdated dependencies with [cargo-outdated](https://github.com/kbknapp/cargo-outdated) `cargo outdated -d 1`. ### Publishing Bump the version in `Cargo.toml` and then run `cargo publish`.