crossbind
GitHub

A C API from JavaScript

A C library's own functions are callable as they are. Its handles, its out-parameters and its constants cross too.

sqlite3_open returns the database through a sqlite3 **. allocPointer(1) makes room for that pointer and readPointerAt reads it back as a handle, which later calls take as their sqlite3 *. SQLITE_OK is a #define, bound because main.js imports it.

null stands for a C NULL, here for the callback and the two pointers sqlite3_exec can do without. Nothing closes the database for you: a C API is tidied up by hand, as sqlite3_close does here.

Try it
Insert three more rows with another sqlite3_exec and print sqlite3_changes again.
Open in playground
Runs without a compile until the C++, Rust, packages or imports change.
Press Run, or Ctrl+Enter, to run main.js.
Type to search every guide page and section.
↑↓ navigate↵ openesc close