A V wrapper for duckdb. This library is now in beta and should be safe to use in most scenarios. Should work on Linux, Windows and MacOS with V version 0.4.x. It requires the library version (libduckdb*
) of DuckDB (see https://github.com/duckdb/duckdb/releases
)
The DuckDB library is automatically downloaded and managed for you! The project includes a V-native installer that:
- Cross-platform: Works on Linux, macOS, and Windows
- Automatically detects your operating system and architecture
- Downloads the latest compatible DuckDB library
- Installs it correctly for your platform
- Keeps it updated when new versions are available
# Install/update the DuckDB library for your platform (dynamic linking)
make install-libs
# Install for static linking (Linux only)
make install-libs-static
# Or run the full setup (install libs + run tests)
make setup
If you prefer manual installation:
- Download the latest DuckDB (
libduckdb*.zip
) for your OS fromhttps://github.com/duckdb/duckdb/releases
- Pick the
.so
(Linux),.dll
(Windows), or.dylib
(OS X) file and rename it tolibduckdb.so
,libduckdb.dll
, orlibduckdb.dylib
accordingly - Copy or move the file to the root directory where your V code is, or to a subdirectory called
thirdparty
or set a global variable calledLIBDUCKDB_DIR
v install https://github.com/rodabt/vduckdb
// example.v
import vduckdb
fn main() {
mut vdb := vduckdb.DuckDB{}
println('vduckdb version: ${vduckdb.version()}')
println('duckdb version: ${vduckdb.duckdb_library_version()}')
_ := vdb.open(':memory:')!
db_file := 'https://gist.githubusercontent.com/Sharanya1307/631c9f66e5709dbace46b5ed6672381e/raw/4329c1980eac3a71b881b18757a5bfabd2a95a1e/people-100.csv'
mut q := "select * from '${db_file}' limit 10"
println('\nQuery: ${q}')
_ := vdb.query(q)!
println('\nColumns and types: ${vdb.columns}')
println('\nExecution time: ${vdb.time_ms}')
println('\n Results as table to terminal:')
println(vdb.print_table(max_rows: 10, mode: 'box')) // other options are: ascii and md
q = 'select "First Name", "Sex" from \'${db_file}\' limit 5'
println('\nData from \'${q}\' as []map[string]string:')
_ := vdb.query(q)!
out := vdb.get_array_as_string()
println(out)
first_row := vdb.get_first_row()
println(first_row)
println('\nManaging errors...')
q = "invalid query..."
vdb.query(q) or {
eprintln(err.msg())
}
vdb.close()
}
For example in Linux if libduckdb.so
is in the same directory of your code or is in the thirdparty
sub directory, then you can run:
$ v run example.v
Otherwise you have to specify the directory with the LIBDUCKDB_DIR
enviromental variable like this:
LIBDUCKDB_DIR=/home/user/libdir v run .
Run v doc vduckdb
or make docs
to generate static HTML documentation in docs
folder
# Install/update DuckDB library for current platform (dynamic linking)
make install-libs
# Install DuckDB library for static linking (Linux only)
make install-libs-static
# Clean downloaded libraries
make clean-libs
# Run tests
make test
# Full project setup (install libs + run tests)
make setup
# Format code
make fmt
# Generate documentation
make docs
- Define as module
- Added tests
- Write base documentation
- Download and install required dependencies
- Map all relevant definitions from
duckvdb.h
header file to their V counterparts - Create convenience functions and data wrappers
- Add website and tutorials
- Build integration with V ORM
Pull requests are welcome
The project includes a V-native installer that works on all platforms:
src/install_duckdb.v
- Cross-platform DuckDB library installer written in V- No external dependencies - everything runs natively in V
For Linux users who want better performance and no runtime library dependencies:
# Install static library
make install-libs-static
# Compile with static linking
v -cflags "-static" your_program.v
Benefits of static linking:
- ⚡ Better performance - No dynamic library loading overhead
- 📦 Self-contained - No external library dependencies at runtime
- 🚀 Faster startup - No library resolution delays
- 🔒 More secure - No library injection vulnerabilities
Note: Static linking is only available on Linux platforms where DuckDB provides libduckdb_static.a
.
The DuckDB library is automatically managed and should not be committed to the repository. The .gitignore
file ensures that:
thirdparty/
directory is excluded- Library files (
.dylib
,.so
,.dll
) are excluded - Build artifacts are excluded