summaryrefslogtreecommitdiff
path: root/doc/extensions.adoc
diff options
context:
space:
mode:
authorJohn Turner <jturner.usa@gmail.com>2025-09-14 00:16:10 -0400
committerJohn Turner <jturner.usa@gmail.com>2025-09-14 00:16:10 -0400
commitefcea3a80da7c4479d5fe168435ecc9fd06bdc72 (patch)
tree5cb0177e17b1b00a177f2e830e809f606334571b /doc/extensions.adoc
downloadsqlite-kv-bench-efcea3a80da7c4479d5fe168435ecc9fd06bdc72.tar.gz
Squashed 'subprojects/boost-sqlite/' content from commit 3378e35
git-subtree-dir: subprojects/boost-sqlite git-subtree-split: 3378e353705271e569cf4ba15c467b840a39798c
Diffstat (limited to 'doc/extensions.adoc')
-rw-r--r--doc/extensions.adoc41
1 files changed, 41 insertions, 0 deletions
diff --git a/doc/extensions.adoc b/doc/extensions.adoc
new file mode 100644
index 0000000..528fb39
--- /dev/null
+++ b/doc/extensions.adoc
@@ -0,0 +1,41 @@
+= Extension Modules
+
+This library can also be used to https://www.sqlite.org/loadext.html::[run-time loadable extensions]
+that can be used by other applications, e.g. the `sqlite3` CLI.
+
+In order to write this, you'll need to include `boost/sqlite/extension.hpp`,
+and write a named module like so:
+
+[source,cpp]
+----
+BOOST_SQLITE_EXTENSION(testlibrary, conn)
+{
+ // create a function that can be used in the plugin
+ create_scalar_function(
+ conn, "assert",
+ [](boost::sqlite::context<>, boost::span<boost::sqlite::value, 1u> sp)
+ {
+ if (sp.front().get_int() == 0)
+ throw std::logic_error("assertion failed");
+ });
+}
+----
+
+[source,sqlite]
+----
+SELECT load_extension('./test_library');
+
+select assert((3 * 4) = 12);
+----
+
+In order to build this, you'll to link against `Boost::sqlite_ext`
+instead of `Boost::sqlite`.
+
+Including the `extension.hpp` header will also define
+`BOOST_SQLITE_COMPILE_EXTENSION`, which will include `sqlite3ext.h`
+instead of `sqlite3.h` and create an inline namespace `ext` inside
+`boost::sqlite`.
+
+This prevents linker issues, but will not allow you to mix extension
+and non-extension code in one translation unit.
+