C++ SQLite HTTP Proxy & JSON Serializer
A statically compiled, schema-agnostic HTTP daemon that executes raw SQL queries against a local SQLite database and dynamically serializes the result cursors into structured JSON payloads.
Tech stack
- Languages
- Frameworks & libraries
- Tools
Performance & metrics
- Extremely low latency achieved by compiling directly to native machine code, bypassing the heavy garbage collection pauses inherent to traditional backend runtimes (Node.js/JVM)
- Zero-copy string casting during result set iteration, mapping
sqlite3_column_textraw pointers directly into the JSON response buffer
Why I built it
Interfacing frontend applications or lightweight network clients directly with SQLite typically requires heavy native driver bindings or complex ORMs. I engineered this standalone C++ daemon to act as a highly performant intermediary. It exposes the underlying SQLite engine over standard HTTP, allowing clients to dispatch raw SQL strings and receive clean JSON data structures without managing native database state.
Architecture & decisions
The core HTTP multiplexing is handled via the header-only cpp-httplib library. To prevent address-in-use exceptions during deployment, the initialization routine hooks directly into the Windows Socket API (Winsock2), sequentially probing network interfaces via bind() to lock an available TCP port. The database engine heavily leverages the SQLite3 C API. To handle arbitrary SQL queries without predefined data models, the execution loop dynamically queries the result schema at runtime using sqlite3_column_count and sqlite3_column_name, mapping the raw C-string pointers directly into an nlohmann/json matrix before returning the HTTP payload.
Key features
- 01Dynamic, schema-agnostic execution engine mapping arbitrary SQL result sets directly to JSON matrices
- 02Native OS-level TCP port probing and allocation utilizing the Windows Socket API (Winsock2)
- 03System-level table reflection (
sqlite_master) exposed via dedicated HTTP endpoints - 04Thread-safe request multiplexing using
cpp-httplibdirectly coupled to the SQLite cursor iteration