summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--sqlite.zig16
1 files changed, 11 insertions, 5 deletions
diff --git a/sqlite.zig b/sqlite.zig
index d521175..4fd06df 100644
--- a/sqlite.zig
+++ b/sqlite.zig
@@ -21,6 +21,7 @@ const getDetailedErrorFromResultCode = errors.getDetailedErrorFromResultCode;
21 21
22const getTestDb = @import("test.zig").getTestDb; 22const getTestDb = @import("test.zig").getTestDb;
23pub const vtab = @import("vtab.zig"); 23pub const vtab = @import("vtab.zig");
24
24const helpers = @import("helpers.zig"); 25const helpers = @import("helpers.zig");
25 26
26test { 27test {
@@ -29,6 +30,11 @@ test {
29 30
30const logger = std.log.scoped(.sqlite); 31const logger = std.log.scoped(.sqlite);
31 32
33fn isStruct(comptime typ: type) bool {
34 const type_info = @typeInfo(typ);
35 return type_info == .Struct;
36}
37
32/// Text is used to represent a SQLite TEXT value when binding a parameter or reading a column. 38/// Text is used to represent a SQLite TEXT value when binding a parameter or reading a column.
33pub const Text = struct { data: []const u8 }; 39pub const Text = struct { data: []const u8 };
34 40
@@ -1308,7 +1314,7 @@ pub fn Iterator(comptime Type: type) type {
1308 } 1314 }
1309 1315
1310 fn readPointer(self: *Self, comptime PointerType: type, options: anytype, i: usize) !PointerType { 1316 fn readPointer(self: *Self, comptime PointerType: type, options: anytype, i: usize) !PointerType {
1311 if (!comptime std.meta.trait.is(.Struct)(@TypeOf(options))) { 1317 if (!comptime isStruct(@TypeOf(options))) {
1312 @compileError("options passed to readPointer must be a struct"); 1318 @compileError("options passed to readPointer must be a struct");
1313 } 1319 }
1314 if (!comptime std.meta.trait.hasField("allocator")(@TypeOf(options))) { 1320 if (!comptime std.meta.trait.hasField("allocator")(@TypeOf(options))) {
@@ -1339,7 +1345,7 @@ pub fn Iterator(comptime Type: type) type {
1339 } 1345 }
1340 1346
1341 fn readOptional(self: *Self, comptime OptionalType: type, options: anytype, _i: usize) !OptionalType { 1347 fn readOptional(self: *Self, comptime OptionalType: type, options: anytype, _i: usize) !OptionalType {
1342 if (!comptime std.meta.trait.is(.Struct)(@TypeOf(options))) { 1348 if (!comptime isStruct(@TypeOf(options))) {
1343 @compileError("options passed to readOptional must be a struct"); 1349 @compileError("options passed to readOptional must be a struct");
1344 } 1350 }
1345 1351
@@ -1384,7 +1390,7 @@ pub fn Iterator(comptime Type: type) type {
1384 // 1390 //
1385 // TODO(vincent): add comptime checks for the fields/columns. 1391 // TODO(vincent): add comptime checks for the fields/columns.
1386 fn readStruct(self: *Self, options: anytype) !Type { 1392 fn readStruct(self: *Self, options: anytype) !Type {
1387 if (!comptime std.meta.trait.is(.Struct)(@TypeOf(options))) { 1393 if (!comptime isStruct(@TypeOf(options))) {
1388 @compileError("options passed to readStruct must be a struct"); 1394 @compileError("options passed to readStruct must be a struct");
1389 } 1395 }
1390 1396
@@ -1402,7 +1408,7 @@ pub fn Iterator(comptime Type: type) type {
1402 } 1408 }
1403 1409
1404 fn readField(self: *Self, comptime FieldType: type, options: anytype, i: usize) !FieldType { 1410 fn readField(self: *Self, comptime FieldType: type, options: anytype, i: usize) !FieldType {
1405 if (!comptime std.meta.trait.is(.Struct)(@TypeOf(options))) { 1411 if (!comptime isStruct(@TypeOf(options))) {
1406 @compileError("options passed to readField must be a struct"); 1412 @compileError("options passed to readField must be a struct");
1407 } 1413 }
1408 1414
@@ -2013,7 +2019,7 @@ pub fn Statement(comptime opts: StatementOptions, comptime query: anytype) type
2013 /// The types are checked at comptime. 2019 /// The types are checked at comptime.
2014 fn bind(self: *Self, options: anytype, values: anytype) !void { 2020 fn bind(self: *Self, options: anytype, values: anytype) !void {
2015 const StructType = @TypeOf(values); 2021 const StructType = @TypeOf(values);
2016 if (!comptime std.meta.trait.is(.Struct)(@TypeOf(values))) { 2022 if (!comptime isStruct(StructType)) {
2017 @compileError("options passed to Statement.bind must be a struct (DynamicStatement supports runtime slices)"); 2023 @compileError("options passed to Statement.bind must be a struct (DynamicStatement supports runtime slices)");
2018 } 2024 }
2019 2025