crossbind
GitHub

A class around a C API

A few lines of C++ turn a C API into a class: the constructor opens, the destructor closes, and a status code becomes an exception.

database.h includes sqlite3.h and keeps the sqlite3 * private, so JavaScript sees no pointer. await new Database() opens the database, run executes a statement, and delete() runs the destructor, which closes it.

This is the pattern for whatever the generator does not bind as it is, and for an API you want shaped for JavaScript. Wrapping what does not fit has more of it.

Try it
Run a statement with a typo in it inside a try, and print the error the class throws.
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