diff options
| author | 2023-11-23 20:58:55 +0100 | |
|---|---|---|
| committer | 2023-11-23 21:09:23 +0100 | |
| commit | 40337a755b4855e3ca83659a9f943bb4cb9008f8 (patch) | |
| tree | 9abdfcf4c56c0e8bcb452a5f6cf77b497f36bbcc | |
| parent | fix preprocess_files (diff) | |
| download | zig-sqlite-40337a755b4855e3ca83659a9f943bb4cb9008f8.tar.gz zig-sqlite-40337a755b4855e3ca83659a9f943bb4cb9008f8.tar.xz zig-sqlite-40337a755b4855e3ca83659a9f943bb4cb9008f8.zip | |
rewrite a helper to check if a type is a struct
std.meta.trait doesn't exist anymore.
Diffstat (limited to '')
| -rw-r--r-- | sqlite.zig | 16 |
1 files changed, 11 insertions, 5 deletions
| @@ -21,6 +21,7 @@ const getDetailedErrorFromResultCode = errors.getDetailedErrorFromResultCode; | |||
| 21 | 21 | ||
| 22 | const getTestDb = @import("test.zig").getTestDb; | 22 | const getTestDb = @import("test.zig").getTestDb; |
| 23 | pub const vtab = @import("vtab.zig"); | 23 | pub const vtab = @import("vtab.zig"); |
| 24 | |||
| 24 | const helpers = @import("helpers.zig"); | 25 | const helpers = @import("helpers.zig"); |
| 25 | 26 | ||
| 26 | test { | 27 | test { |
| @@ -29,6 +30,11 @@ test { | |||
| 29 | 30 | ||
| 30 | const logger = std.log.scoped(.sqlite); | 31 | const logger = std.log.scoped(.sqlite); |
| 31 | 32 | ||
| 33 | fn 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. |
| 33 | pub const Text = struct { data: []const u8 }; | 39 | pub 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 | ||