summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Vincent Rischmann2020-12-27 18:42:12 +0100
committerGravatar Vincent Rischmann2020-12-29 23:26:38 +0100
commitbfab3c6664fab3e6190a2d499ab5a59a30aaa216 (patch)
tree6cd44644abd4a4b9012f9d1cecf5888a3d25ee31
parentreadme: replace sourcehut repository url with github (diff)
downloadzig-sqlite-bfab3c6664fab3e6190a2d499ab5a59a30aaa216.tar.gz
zig-sqlite-bfab3c6664fab3e6190a2d499ab5a59a30aaa216.tar.xz
zig-sqlite-bfab3c6664fab3e6190a2d499ab5a59a30aaa216.zip
add the threading mode
-rw-r--r--sqlite.zig14
1 files changed, 14 insertions, 0 deletions
diff --git a/sqlite.zig b/sqlite.zig
index b756fd8..dd4469b 100644
--- a/sqlite.zig
+++ b/sqlite.zig
@@ -12,6 +12,16 @@ usingnamespace @import("query.zig");
12 12
13const logger = std.log.scoped(.sqlite); 13const logger = std.log.scoped(.sqlite);
14 14
15pub const ThreadingMode = enum {
16 SingleThread,
17 MultiThread,
18 Serialized,
19};
20
21fn isThreadSafe() bool {
22 return c.sqlite3_threadsafe() > 0;
23}
24
15/// Db is a wrapper around a SQLite database, providing high-level functions for executing queries. 25/// Db is a wrapper around a SQLite database, providing high-level functions for executing queries.
16/// A Db can be opened with a file database or a in-memory database: 26/// A Db can be opened with a file database or a in-memory database:
17/// 27///
@@ -40,6 +50,10 @@ pub const Db = struct {
40 self.allocator = allocator; 50 self.allocator = allocator;
41 51
42 const mode: Mode = if (@hasField(@TypeOf(options), "mode")) options.mode else .Memory; 52 const mode: Mode = if (@hasField(@TypeOf(options), "mode")) options.mode else .Memory;
53 // Validate the threading mode
54 if (options.threading_mode != .SingleThread and !isThreadSafe()) {
55 return error.CannotUseSingleThreadedSQLite;
56 }
43 57
44 switch (mode) { 58 switch (mode) {
45 .File => |path| { 59 .File => |path| {