From 6c22535e42a2c29aed96a14fdec5f1359f603dd5 Mon Sep 17 00:00:00 2001 From: Kenta Iwasaki Date: Thu, 26 Aug 2021 05:42:21 +0900 Subject: sqlite: expose c import, add 'shared_cache' to init flags Expose the C import to sqlite.h. Making a separate call to @cImport outside of the library will cause Zig to regenerate all definitions in sqlite.h. The regenerated definitions (i.e. structs, enums) would not be equivalent to the definitions imported in by this library. This causes problems in the case one wants to manually wrap SQLite structs, pointers, and enums with the helpers provided in this library. Added 'shared_cache' to init flags in order to allow having the same backing table and statement cache shared amongst all connections pointed to the same database file. --- sqlite.zig | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'sqlite.zig') diff --git a/sqlite.zig b/sqlite.zig index abeea55..e88fb64 100644 --- a/sqlite.zig +++ b/sqlite.zig @@ -5,7 +5,7 @@ const io = std.io; const mem = std.mem; const testing = std.testing; -const c = @cImport({ +pub const c = @cImport({ @cInclude("sqlite3.h"); }); @@ -233,6 +233,12 @@ pub const InitOptions = struct { /// Defaults to Serialized. threading_mode: ThreadingMode = .Serialized, + /// shared_cache controls whether or not concurrent SQLite + /// connections share the same cache. + /// + /// Defaults to false. + shared_cache: bool = false, + /// if provided, diags will be populated in case of failures. diags: ?*Diagnostics = null, }; @@ -327,6 +333,9 @@ pub const Db = struct { if (options.open_flags.create) { flags |= c.SQLITE_OPEN_CREATE; } + if (options.shared_cache) { + flags |= c.SQLITE_OPEN_SHAREDCACHE; + } switch (options.threading_mode) { .MultiThread => flags |= c.SQLITE_OPEN_NOMUTEX, .Serialized => flags |= c.SQLITE_OPEN_FULLMUTEX, -- cgit v1.2.3