-
-
Save patrick-palka/00f002c76ad35ec55957716879c87ebe to your computer and use it in GitHub Desktop.
Automatic marshaling of C++ functions into SQL user functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output:
!dlrow olleh