VillageSQL is a drop-in replacement for MySQL with extensions.
All examples in this guide work on VillageSQL. Install Now →
When to Choose C++
C++ is the right choice when:- Your team already has a C++ codebase and wants to keep the extension in the same language
- You need custom types with precise binary layouts (the C++ type builder is the most complete API)
- You’re working with existing C++ libraries that you want to expose as SQL functions
Prerequisites
Before writing extension code, you need a VillageSQL build — extensions link against the server’s SDK headers and build tree. You also need:- C++17 compiler — GCC 8+, Clang 8+, or MSVC 2019+
- CMake 3.18+ — the extension template uses CMake
CMake Setup
The fastest way to start is with the vsql-extension-template. Fork it or clone it:CMakeLists.txt handles the VEF build setup for you — copy the template and adapt it rather than writing CMake from scratch. Configure the build directory with -DVillageSQL_BUILD_DIR:
-DVillageSQL_BUILD_DIR tells CMake where your VillageSQL build lives so it can find the SDK headers. This produces a .veb file in the build output. See Creating Extensions and the vsql-extension-template for the full CMake setup.
A Minimal VDF in C++
Include the VEF SDK header and use the builder API to register your function. Here’s a complete extension implementing a string reversal function:- Include
<villagesql/vsql.h>, not<villagesql/extension.h>(that’s the old V1 header) - Typed argument wrappers (
StringArg,IntArg,RealArg) check nulls and expose typed values — no raw pointer arithmetic out.set_null(),out.warning(msg), andout.error(msg)are the three non-success returnsVEF_GENERATE_ENTRY_POINTStakes amake_extension()builder, not a raw struct
.deterministic() to the builder chain:
.deterministic() when it’s actually true.
Building
After the cmake configure step from the CMake setup section above, build and install:make install copies the .veb file to your VillageSQL extensions directory.
Installing and Testing
Connect to VillageSQL and install the extension:mysql-test/t/:
See also
- Creating Extensions — full C++ SDK reference: typed wrappers, custom types, aggregates, system variables
- Extension API Reference — VDF contracts, null handling, buffer sizing, error semantics
- Writing Rust Extensions — the Rust path for the same task

