authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-08-17 23:07:31-07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-08-17 23:07:31-07:00
log8c99d8f6b67eb7c16d6bd7bf8f95153798b3240e
tree389f7bc5dc0538fa89e67c7ac230d0c4af92c7ce
parentcd19192e296443273d1572b297cbc628f11e99b9
signature Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

sqlite3: add all the modern recommended pragmas

https://mort.coffee/home/sqlite-editions/ https://kerkour.com/sqlite-for-servers https://micrologics.org/blog/sqlite-in-production-optimizing-wal-mode-concurrency-and-vfs-layers-for-low-latency-app-servers

1 files changed, 13 insertions(+), 0 deletions(-)

src/sqlite3.zig+13
......@@ -9,6 +9,19 @@ const Self = @This();
99db: *c.sqlite3,
1010
1111pub fn connect(allocator: std.mem.Allocator, path: [:0]const u8) !Self {
12 var driver: Self = try .connect_only(allocator, path);
13 errdefer driver.close();
14 _ = try driver.first(allocator, void, "PRAGMA journal_mode = WAL", .{});
15 _ = try driver.first(allocator, void, "PRAGMA busy_timeout = 5000", .{});
16 _ = try driver.first(allocator, void, "PRAGMA synchronous = NORMAL", .{});
17 _ = try driver.first(allocator, void, "PRAGMA cache_size = 1000000000", .{});
18 _ = try driver.first(allocator, void, "PRAGMA foreign_keys = true", .{});
19 _ = try driver.first(allocator, void, "PRAGMA temp_store = memory", .{});
20 _ = try driver.first(allocator, void, "PRAGMA mmap_size = 1073741824", .{});
21 _ = try driver.first(allocator, void, "PRAGMA auto_vacuum = INCREMENTAL", .{});
22 return driver;
23}
24pub fn connect_only(allocator: std.mem.Allocator, path: [:0]const u8) !Self {
1225 std.log.scoped(.zorm).info("connecting to {s} @ {s}", .{ "sqlite3", path });
1326 _ = allocator;
1427 var db: ?*c.sqlite3 = null;