Skip to content

Instantly share code, notes, and snippets.

@patrick-palka patrick-palka/marshal.cc Secret
Last active Aug 21, 2019

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

commented Aug 21, 2019

Output: !dlrow olleh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.