diff options
| author | 2023-07-02 18:34:22 -0700 | |
|---|---|---|
| committer | 2023-07-06 13:55:56 +0200 | |
| commit | 236bc4202649894e3b1bf03082ef845c2d86b950 (patch) | |
| tree | 31fdb72819da2a6bc0908e85b11f3ab416820fd1 /sqlite.zig | |
| parent | Merge branch 'update-latest-zig' (diff) | |
| download | zig-sqlite-236bc4202649894e3b1bf03082ef845c2d86b950.tar.gz zig-sqlite-236bc4202649894e3b1bf03082ef845c2d86b950.tar.xz zig-sqlite-236bc4202649894e3b1bf03082ef845c2d86b950.zip | |
support packed structs as columns backed by their int type
Diffstat (limited to 'sqlite.zig')
| -rw-r--r-- | sqlite.zig | 9 |
1 files changed, 7 insertions, 2 deletions
| @@ -1444,7 +1444,8 @@ pub fn Iterator(comptime Type: type) type { | |||
| 1444 | } | 1444 | } |
| 1445 | @compileError("enum column " ++ @typeName(FieldType) ++ " must have a BaseType of either string or int"); | 1445 | @compileError("enum column " ++ @typeName(FieldType) ++ " must have a BaseType of either string or int"); |
| 1446 | }, | 1446 | }, |
| 1447 | .Struct => { | 1447 | .Struct => |TI| { |
| 1448 | if (TI.layout == .Packed) return @bitCast(FieldType, try self.readInt(TI.backing_integer.?, i)); | ||
| 1448 | const inner_value = try self.readField(FieldType.BaseType, options, i); | 1449 | const inner_value = try self.readField(FieldType.BaseType, options, i); |
| 1449 | return try FieldType.readField(options.allocator, inner_value); | 1450 | return try FieldType.readField(options.allocator, inner_value); |
| 1450 | }, | 1451 | }, |
| @@ -1650,7 +1651,11 @@ pub const DynamicStatement = struct { | |||
| 1650 | @compileError("enum column " ++ @typeName(FieldType) ++ " must have a BaseType of either string or int to bind"); | 1651 | @compileError("enum column " ++ @typeName(FieldType) ++ " must have a BaseType of either string or int to bind"); |
| 1651 | } | 1652 | } |
| 1652 | }, | 1653 | }, |
| 1653 | .Struct => { | 1654 | .Struct => |info| { |
| 1655 | if (info.layout == .Packed) { | ||
| 1656 | try self.bindField(info.backing_integer.?, options, field_name, i, @bitCast(info.backing_integer.?, field)); | ||
| 1657 | return; | ||
| 1658 | } | ||
| 1654 | if (!comptime std.meta.trait.hasFn("bindField")(FieldType)) { | 1659 | if (!comptime std.meta.trait.hasFn("bindField")(FieldType)) { |
| 1655 | @compileError("cannot bind field " ++ field_name ++ " of type " ++ @typeName(FieldType) ++ ", consider implementing the bindField() method"); | 1660 | @compileError("cannot bind field " ++ field_name ++ " of type " ++ @typeName(FieldType) ++ ", consider implementing the bindField() method"); |
| 1656 | } | 1661 | } |