Skip to content

Instantly share code, notes, and snippets.

@patrick-palka
Last active August 21, 2019 22:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patrick-palka/00f002c76ad35ec55957716879c87ebe to your computer and use it in GitHub Desktop.
Save patrick-palka/00f002c76ad35ec55957716879c87ebe to your computer and use it in GitHub Desktop.
Automatic marshaling of C++ functions into SQL user functions
#include "SQLiteWrapper.h"
std::string reverse(std::string str) {
std::reverse(str.begin(), str.end());
return str;
}
int main(void) {
static const char reverse_name[] = "reverse";
sqlite::createFunction<reverse_name>(&reverse);
static const char db_name[] = ":memory:";
using db = sqlite::Database<db_name>;
static const char select_query[] = "select reverse(?1)";
auto fetch_row = db::query<select_query>("hello world!");
std::string_view str;
while (fetch_row(str)) {
std::cout << str << std::endl;
}
}
@patrick-palka
Copy link
Author

Output: !dlrow olleh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment