diff options
| author | 2021-08-26 05:42:21 +0900 | |
|---|---|---|
| committer | 2021-08-26 05:42:21 +0900 | |
| commit | 6c22535e42a2c29aed96a14fdec5f1359f603dd5 (patch) | |
| tree | be428a9aa4868c0e967e94fdeca5c9c1ef64ec84 | |
| parent | Merge pull request #42 from nektro/master (diff) | |
| download | zig-sqlite-6c22535e42a2c29aed96a14fdec5f1359f603dd5.tar.gz zig-sqlite-6c22535e42a2c29aed96a14fdec5f1359f603dd5.tar.xz zig-sqlite-6c22535e42a2c29aed96a14fdec5f1359f603dd5.zip | |
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.
| -rw-r--r-- | sqlite.zig | 11 |
1 files changed, 10 insertions, 1 deletions
| @@ -5,7 +5,7 @@ const io = std.io; | |||
| 5 | const mem = std.mem; | 5 | const mem = std.mem; |
| 6 | const testing = std.testing; | 6 | const testing = std.testing; |
| 7 | 7 | ||
| 8 | const c = @cImport({ | 8 | pub const c = @cImport({ |
| 9 | @cInclude("sqlite3.h"); | 9 | @cInclude("sqlite3.h"); |
| 10 | }); | 10 | }); |
| 11 | 11 | ||
| @@ -233,6 +233,12 @@ pub const InitOptions = struct { | |||
| 233 | /// Defaults to Serialized. | 233 | /// Defaults to Serialized. |
| 234 | threading_mode: ThreadingMode = .Serialized, | 234 | threading_mode: ThreadingMode = .Serialized, |
| 235 | 235 | ||
| 236 | /// shared_cache controls whether or not concurrent SQLite | ||
| 237 | /// connections share the same cache. | ||
| 238 | /// | ||
| 239 | /// Defaults to false. | ||
| 240 | shared_cache: bool = false, | ||
| 241 | |||
| 236 | /// if provided, diags will be populated in case of failures. | 242 | /// if provided, diags will be populated in case of failures. |
| 237 | diags: ?*Diagnostics = null, | 243 | diags: ?*Diagnostics = null, |
| 238 | }; | 244 | }; |
| @@ -327,6 +333,9 @@ pub const Db = struct { | |||
| 327 | if (options.open_flags.create) { | 333 | if (options.open_flags.create) { |
| 328 | flags |= c.SQLITE_OPEN_CREATE; | 334 | flags |= c.SQLITE_OPEN_CREATE; |
| 329 | } | 335 | } |
| 336 | if (options.shared_cache) { | ||
| 337 | flags |= c.SQLITE_OPEN_SHAREDCACHE; | ||
| 338 | } | ||
| 330 | switch (options.threading_mode) { | 339 | switch (options.threading_mode) { |
| 331 | .MultiThread => flags |= c.SQLITE_OPEN_NOMUTEX, | 340 | .MultiThread => flags |= c.SQLITE_OPEN_NOMUTEX, |
| 332 | .Serialized => flags |= c.SQLITE_OPEN_FULLMUTEX, | 341 | .Serialized => flags |= c.SQLITE_OPEN_FULLMUTEX, |