diff options
Diffstat (limited to 'sqlite.zig')
| -rw-r--r-- | sqlite.zig | 35 |
1 files changed, 20 insertions, 15 deletions
| @@ -569,27 +569,32 @@ pub fn Iterator(comptime Type: type) type { | |||
| 569 | 569 | ||
| 570 | inline for (@typeInfo(Type).Struct.fields) |field, _i| { | 570 | inline for (@typeInfo(Type).Struct.fields) |field, _i| { |
| 571 | const i = @as(usize, _i); | 571 | const i = @as(usize, _i); |
| 572 | const field_type_info = @typeInfo(field.field_type); | 572 | |
| 573 | 573 | const ret = try self.readField(field.field_type, i, options); | |
| 574 | const ret = switch (field.field_type) { | ||
| 575 | Blob => try self.readBytes(Blob, options.allocator, i, .Blob), | ||
| 576 | Text => try self.readBytes(Text, options.allocator, i, .Text), | ||
| 577 | else => switch (field_type_info) { | ||
| 578 | .Int => try self.readInt(field.field_type, i), | ||
| 579 | .Float => try self.readFloat(field.field_type, i), | ||
| 580 | .Bool => try self.readBool(i), | ||
| 581 | .Void => {}, | ||
| 582 | .Array => try self.readArray(field.field_type, i), | ||
| 583 | .Pointer => try self.readPointer(field.field_type, options.allocator, i), | ||
| 584 | else => @compileError("cannot populate field " ++ field.name ++ " of type " ++ @typeName(field.field_type)), | ||
| 585 | }, | ||
| 586 | }; | ||
| 587 | 574 | ||
| 588 | @field(value, field.name) = ret; | 575 | @field(value, field.name) = ret; |
| 589 | } | 576 | } |
| 590 | 577 | ||
| 591 | return value; | 578 | return value; |
| 592 | } | 579 | } |
| 580 | |||
| 581 | fn readField(self: *Self, comptime FieldType: type, i: usize, options: anytype) !FieldType { | ||
| 582 | const field_type_info = @typeInfo(FieldType); | ||
| 583 | |||
| 584 | return switch (FieldType) { | ||
| 585 | Blob => try self.readBytes(Blob, options.allocator, i, .Blob), | ||
| 586 | Text => try self.readBytes(Text, options.allocator, i, .Text), | ||
| 587 | else => switch (field_type_info) { | ||
| 588 | .Int => try self.readInt(FieldType, i), | ||
| 589 | .Float => try self.readFloat(FieldType, i), | ||
| 590 | .Bool => try self.readBool(i), | ||
| 591 | .Void => {}, | ||
| 592 | .Array => try self.readArray(FieldType, i), | ||
| 593 | .Pointer => try self.readPointer(FieldType, options.allocator, i), | ||
| 594 | else => @compileError("cannot populate field " ++ field.name ++ " of type " ++ @typeName(FieldType)), | ||
| 595 | }, | ||
| 596 | }; | ||
| 597 | } | ||
| 593 | }; | 598 | }; |
| 594 | } | 599 | } |
| 595 | 600 | ||