diff options
| author | 2023-02-22 23:20:14 +0100 | |
|---|---|---|
| committer | 2023-02-22 23:20:14 +0100 | |
| commit | 1333830fcf6b8e99bb0d9497ceaea79251e5195c (patch) | |
| tree | cacca60e428ad150e021ec5cee0e27cd128e79f3 /sqlite.zig | |
| parent | fix tests (diff) | |
| download | zig-sqlite-1333830fcf6b8e99bb0d9497ceaea79251e5195c.tar.gz zig-sqlite-1333830fcf6b8e99bb0d9497ceaea79251e5195c.tar.xz zig-sqlite-1333830fcf6b8e99bb0d9497ceaea79251e5195c.zip | |
fix for latest zig by running 'zig fmt'
Diffstat (limited to 'sqlite.zig')
| -rw-r--r-- | sqlite.zig | 24 |
1 files changed, 12 insertions, 12 deletions
| @@ -748,7 +748,7 @@ pub const Db = struct { | |||
| 748 | const sqlite_args = argv[0..fn_info.params.len]; | 748 | const sqlite_args = argv[0..fn_info.params.len]; |
| 749 | 749 | ||
| 750 | var fn_args: ArgTuple = undefined; | 750 | var fn_args: ArgTuple = undefined; |
| 751 | inline for (fn_info.params) |arg, i| { | 751 | inline for (fn_info.params, 0..) |arg, i| { |
| 752 | const ArgType = arg.type.?; | 752 | const ArgType = arg.type.?; |
| 753 | helpers.setTypeFromValue(ArgType, &fn_args[i], sqlite_args[i].?); | 753 | helpers.setTypeFromValue(ArgType, &fn_args[i], sqlite_args[i].?); |
| 754 | } | 754 | } |
| @@ -1395,7 +1395,7 @@ pub fn Iterator(comptime Type: type) type { | |||
| 1395 | 1395 | ||
| 1396 | var value: Type = undefined; | 1396 | var value: Type = undefined; |
| 1397 | 1397 | ||
| 1398 | inline for (@typeInfo(Type).Struct.fields) |field, _i| { | 1398 | inline for (@typeInfo(Type).Struct.fields, 0..) |field, _i| { |
| 1399 | const i = @as(usize, _i); | 1399 | const i = @as(usize, _i); |
| 1400 | 1400 | ||
| 1401 | const ret = try self.readField(field.type, options, i); | 1401 | const ret = try self.readField(field.type, options, i); |
| @@ -1721,7 +1721,7 @@ pub const DynamicStatement = struct { | |||
| 1721 | 1721 | ||
| 1722 | switch (@typeInfo(Type)) { | 1722 | switch (@typeInfo(Type)) { |
| 1723 | .Struct => |StructTypeInfo| { | 1723 | .Struct => |StructTypeInfo| { |
| 1724 | inline for (StructTypeInfo.fields) |struct_field, struct_field_i| { | 1724 | inline for (StructTypeInfo.fields, 0..) |struct_field, struct_field_i| { |
| 1725 | const field_value = @field(values, struct_field.name); | 1725 | const field_value = @field(values, struct_field.name); |
| 1726 | 1726 | ||
| 1727 | const i = sqlite3BindParameterIndex(self.stmt, struct_field.name); | 1727 | const i = sqlite3BindParameterIndex(self.stmt, struct_field.name); |
| @@ -1735,7 +1735,7 @@ pub const DynamicStatement = struct { | |||
| 1735 | .Pointer => |PointerTypeInfo| { | 1735 | .Pointer => |PointerTypeInfo| { |
| 1736 | switch (PointerTypeInfo.size) { | 1736 | switch (PointerTypeInfo.size) { |
| 1737 | .Slice => { | 1737 | .Slice => { |
| 1738 | for (values) |value_to_bind, index| { | 1738 | for (values, 0..) |value_to_bind, index| { |
| 1739 | try self.bindField(PointerTypeInfo.child, options, "unknown", @intCast(c_int, index), value_to_bind); | 1739 | try self.bindField(PointerTypeInfo.child, options, "unknown", @intCast(c_int, index), value_to_bind); |
| 1740 | } | 1740 | } |
| 1741 | }, | 1741 | }, |
| @@ -1743,7 +1743,7 @@ pub const DynamicStatement = struct { | |||
| 1743 | } | 1743 | } |
| 1744 | }, | 1744 | }, |
| 1745 | .Array => |ArrayTypeInfo| { | 1745 | .Array => |ArrayTypeInfo| { |
| 1746 | for (values) |value_to_bind, index| { | 1746 | for (values, 0..) |value_to_bind, index| { |
| 1747 | try self.bindField(ArrayTypeInfo.child, options, "unknown", @intCast(c_int, index), value_to_bind); | 1747 | try self.bindField(ArrayTypeInfo.child, options, "unknown", @intCast(c_int, index), value_to_bind); |
| 1748 | } | 1748 | } |
| 1749 | }, | 1749 | }, |
| @@ -2025,7 +2025,7 @@ pub fn Statement(comptime opts: StatementOptions, comptime query: anytype) type | |||
| 2025 | })); | 2025 | })); |
| 2026 | } | 2026 | } |
| 2027 | 2027 | ||
| 2028 | inline for (StructTypeInfo.fields) |struct_field, _i| { | 2028 | inline for (StructTypeInfo.fields, 0..) |struct_field, _i| { |
| 2029 | const bind_marker = query.bind_markers[_i]; | 2029 | const bind_marker = query.bind_markers[_i]; |
| 2030 | if (bind_marker.typed) |typ| { | 2030 | if (bind_marker.typed) |typ| { |
| 2031 | const FieldTypeInfo = @typeInfo(struct_field.type); | 2031 | const FieldTypeInfo = @typeInfo(struct_field.type); |
| @@ -2497,7 +2497,7 @@ test "sqlite: read all users into a struct" { | |||
| 2497 | 2497 | ||
| 2498 | var rows = try stmt.all(TestUser, allocator, .{}, .{}); | 2498 | var rows = try stmt.all(TestUser, allocator, .{}, .{}); |
| 2499 | try testing.expectEqual(@as(usize, 3), rows.len); | 2499 | try testing.expectEqual(@as(usize, 3), rows.len); |
| 2500 | for (rows) |row, i| { | 2500 | for (rows, 0..) |row, i| { |
| 2501 | const exp = test_users[i]; | 2501 | const exp = test_users[i]; |
| 2502 | try testing.expectEqual(exp.id, row.id); | 2502 | try testing.expectEqual(exp.id, row.id); |
| 2503 | try testing.expectEqualStrings(exp.name, row.name); | 2503 | try testing.expectEqualStrings(exp.name, row.name); |
| @@ -2828,7 +2828,7 @@ test "sqlite: bind pointer" { | |||
| 2828 | var stmt = try db.prepare(query); | 2828 | var stmt = try db.prepare(query); |
| 2829 | defer stmt.deinit(); | 2829 | defer stmt.deinit(); |
| 2830 | 2830 | ||
| 2831 | for (test_users) |test_user, i| { | 2831 | for (test_users, 0..) |test_user, i| { |
| 2832 | stmt.reset(); | 2832 | stmt.reset(); |
| 2833 | 2833 | ||
| 2834 | const name = try stmt.oneAlloc([]const u8, allocator, .{}, .{&test_user.id}); | 2834 | const name = try stmt.oneAlloc([]const u8, allocator, .{}, .{&test_user.id}); |
| @@ -2864,7 +2864,7 @@ test "sqlite: read pointers" { | |||
| 2864 | ); | 2864 | ); |
| 2865 | 2865 | ||
| 2866 | try testing.expectEqual(@as(usize, 3), rows.len); | 2866 | try testing.expectEqual(@as(usize, 3), rows.len); |
| 2867 | for (rows) |row, i| { | 2867 | for (rows, 0..) |row, i| { |
| 2868 | const exp = test_users[i]; | 2868 | const exp = test_users[i]; |
| 2869 | try testing.expectEqual(exp.id, row.id.*); | 2869 | try testing.expectEqual(exp.id, row.id.*); |
| 2870 | try testing.expectEqualStrings(exp.name, row.name.*); | 2870 | try testing.expectEqualStrings(exp.name, row.name.*); |
| @@ -2998,7 +2998,7 @@ test "sqlite: statement iterator" { | |||
| 2998 | // Check the data | 2998 | // Check the data |
| 2999 | try testing.expectEqual(expected_rows.items.len, rows.items.len); | 2999 | try testing.expectEqual(expected_rows.items.len, rows.items.len); |
| 3000 | 3000 | ||
| 3001 | for (rows.items) |row, j| { | 3001 | for (rows.items, 0..) |row, j| { |
| 3002 | const exp_row = expected_rows.items[j]; | 3002 | const exp_row = expected_rows.items[j]; |
| 3003 | try testing.expectEqualStrings(exp_row.name, mem.sliceTo(&row.name, 0)); | 3003 | try testing.expectEqualStrings(exp_row.name, mem.sliceTo(&row.name, 0)); |
| 3004 | try testing.expectEqual(exp_row.age, row.age); | 3004 | try testing.expectEqual(exp_row.age, row.age); |
| @@ -3025,7 +3025,7 @@ test "sqlite: statement iterator" { | |||
| 3025 | // Check the data | 3025 | // Check the data |
| 3026 | try testing.expectEqual(expected_rows.items.len, rows.items.len); | 3026 | try testing.expectEqual(expected_rows.items.len, rows.items.len); |
| 3027 | 3027 | ||
| 3028 | for (rows.items) |row, j| { | 3028 | for (rows.items, 0..) |row, j| { |
| 3029 | const exp_row = expected_rows.items[j]; | 3029 | const exp_row = expected_rows.items[j]; |
| 3030 | try testing.expectEqualStrings(exp_row.name, row.name.data); | 3030 | try testing.expectEqualStrings(exp_row.name, row.name.data); |
| 3031 | try testing.expectEqual(exp_row.age, row.age); | 3031 | try testing.expectEqual(exp_row.age, row.age); |
| @@ -3386,7 +3386,7 @@ test "sqlite: bind custom type" { | |||
| 3386 | const rows = try stmt.all(Article, arena.allocator(), .{}, .{}); | 3386 | const rows = try stmt.all(Article, arena.allocator(), .{}, .{}); |
| 3387 | try testing.expectEqual(@as(usize, 20), rows.len); | 3387 | try testing.expectEqual(@as(usize, 20), rows.len); |
| 3388 | 3388 | ||
| 3389 | for (rows) |row, i| { | 3389 | for (rows, 0..) |row, i| { |
| 3390 | var exp_data: MyData = undefined; | 3390 | var exp_data: MyData = undefined; |
| 3391 | mem.set(u8, &exp_data.data, @intCast(u8, i)); | 3391 | mem.set(u8, &exp_data.data, @intCast(u8, i)); |
| 3392 | 3392 | ||