@@ -364,9 +364,9 @@ pub const Access = enum {
364364 pub const default = .read_write ;
365365
366366 pub fn to_string (access : Access ) []const u8 {
367- return inline for (@typeInfo (Access ).@"enum" .fields ) | field | {
368- if (@field (Access , field . name ) == access )
369- break field . name ;
367+ return inline for (@typeInfo (Access ).@"enum" .field_names ) | field_name | {
368+ if (@field (Access , field_name ) == access )
369+ break field_name ;
370370 } else unreachable ;
371371 }
372372};
@@ -383,14 +383,14 @@ fn gen_field_list(comptime T: type, opts: struct { prefix: ?[]const u8 = null })
383383 var buf : [4096 ]u8 = undefined ;
384384 var fbs : std.Io.Writer = .fixed (& buf );
385385
386- inline for (@typeInfo (T ).@"struct" .fields , 0.. ) | field , i | {
386+ inline for (@typeInfo (T ).@"struct" .field_names , 0.. ) | field_name , i | {
387387 if (i != 0 )
388388 fbs .writeAll (", " ) catch unreachable ;
389389
390390 if (opts .prefix ) | prefix |
391391 fbs .print ("{s}." , .{prefix }) catch unreachable ;
392392
393- fbs .print ("{s}" , .{field . name }) catch unreachable ;
393+ fbs .print ("{s}" , .{field_name }) catch unreachable ;
394394 }
395395
396396 const buf_copy = buf ;
@@ -423,9 +423,9 @@ fn gen_sql_table_impl(comptime name: []const u8, comptime T: type) ![:0]const u8
423423 var primary_key_found = T .sql_opts .primary_key == null ;
424424
425425 const info = @typeInfo (T );
426- inline for (info .@"struct" .fields ) | field | {
426+ inline for (info .@"struct" .field_names ) | field_name | {
427427 if (T .sql_opts .primary_key ) | primary_key | {
428- if (std .mem .eql (u8 , primary_key .name , field . name ))
428+ if (std .mem .eql (u8 , primary_key .name , field_name ))
429429 primary_key_found = true ;
430430 }
431431 }
@@ -434,21 +434,21 @@ fn gen_sql_table_impl(comptime name: []const u8, comptime T: type) ![:0]const u8
434434
435435 try fbs .print ("CREATE TABLE {s} (\n " , .{name });
436436 var first = true ;
437- inline for (info .@"struct" .fields ) | field | {
437+ inline for (info .@"struct" .field_names , info .@ "struct" .field_types ) | field_name , field_type | {
438438 if (first ) {
439439 first = false ;
440440 } else {
441441 try fbs .writeAll (",\n " );
442442 }
443- try fbs .print (" {s}" , .{field . name });
444- try fbs .print (" {s}" , .{zig_type_to_sql_type (field . type )});
443+ try fbs .print (" {s}" , .{field_name });
444+ try fbs .print (" {s}" , .{zig_type_to_sql_type (field_type )});
445445
446- const field_type_info = @typeInfo (field . type );
446+ const field_type_info = @typeInfo (field_type );
447447 if (field_type_info != .optional )
448448 try fbs .writeAll (" NOT NULL" );
449449
450450 if (T .sql_opts .primary_key ) | primary_key | {
451- if (std .mem .eql (u8 , primary_key .name , field . name )) {
451+ if (std .mem .eql (u8 , primary_key .name , field_name )) {
452452 try fbs .writeAll (" PRIMARY KEY" );
453453
454454 if (primary_key .autoincrement )
@@ -474,9 +474,9 @@ fn gen_sql_table_impl(comptime name: []const u8, comptime T: type) ![:0]const u8
474474 for (T .sql_opts .foreign_keys ) | foreign_key | {
475475 try fbs .writeAll (",\n " );
476476
477- const field_type = for (@typeInfo (T ).@"struct" .fields ) | field | {
478- if (std .mem .eql (u8 , field . name , foreign_key .name ))
479- break field . type ;
477+ const field_type = for (@typeInfo (T ).@"struct" .field_names , @typeInfo ( T ).@ "struct" .field_types ) | field_name , field_type | {
478+ if (std .mem .eql (u8 , field_name , foreign_key .name ))
479+ break field_type ;
480480 } else unreachable ;
481481
482482 try fbs .print (" FOREIGN KEY ({s}) REFERENCES {s}(id) ON DELETE {s} ON UPDATE {s}\n " , .{
@@ -776,31 +776,31 @@ pub fn get_device_id_by_name(db: *Database, name: []const u8) !?DeviceID {
776776fn scan_row (comptime T : type , allocator : Allocator , row : zqlite.Row ) ! T {
777777 var entry : T = undefined ;
778778 const info = @typeInfo (T ).@"struct" ;
779- inline for (info .fields , 0.. ) | field , i | {
780- if (@typeInfo (field . type ) == .@"enum" ) {
781- if (@hasDecl (field . type , "to_string" ))
782- @field (entry , field . name ) = std .meta .stringToEnum (field . type , row .text (i )) orelse return error .Unknown
779+ inline for (info .field_names , info . field_types , 0.. ) | field_name , field_type , i | {
780+ if (@typeInfo (field_type ) == .@"enum" ) {
781+ if (@hasDecl (field_type , "to_string" ))
782+ @field (entry , field_name ) = std .meta .stringToEnum (field_type , row .text (i )) orelse return error .Unknown
783783 else
784- @field (entry , field . name ) = @enumFromInt (row .int (i ));
785- } else if (@typeInfo (field . type ) == .int ) {
786- @field (entry , field . name ) = @intCast (row .int (i ));
787- } else switch (field . type ) {
784+ @field (entry , field_name ) = @enumFromInt (row .int (i ));
785+ } else if (@typeInfo (field_type ) == .int ) {
786+ @field (entry , field_name ) = @intCast (row .int (i ));
787+ } else switch (field_type ) {
788788 []const u8 = > {
789- @field (entry , field . name ) = try allocator .dupe (u8 , row .text (i ));
789+ @field (entry , field_name ) = try allocator .dupe (u8 , row .text (i ));
790790 },
791791 ? []const u8 = > {
792- @field (entry , field . name ) = if (row .nullableText (i )) | text | try allocator .dupe (u8 , text ) else null ;
792+ @field (entry , field_name ) = if (row .nullableText (i )) | text | try allocator .dupe (u8 , text ) else null ;
793793 },
794794 ? u64 , ? u16 , ? u8 = > {
795- @field (entry , field . name ) = if (row .nullableInt (i )) | value | @intCast (value ) else null ;
795+ @field (entry , field_name ) = if (row .nullableInt (i )) | value | @intCast (value ) else null ;
796796 },
797797 ? StructID , ? EnumID = > {
798- @field (entry , field . name ) = if (row .nullableInt (i )) | value | @enumFromInt (value ) else null ;
798+ @field (entry , field_name ) = if (row .nullableInt (i )) | value | @enumFromInt (value ) else null ;
799799 },
800800 ? Access = > {
801- @field (entry , field . name ) = if (row .nullableText (i )) | text | (std .meta .stringToEnum (Access , text ) orelse return error .Unknown ) else null ;
801+ @field (entry , field_name ) = if (row .nullableText (i )) | text | (std .meta .stringToEnum (Access , text ) orelse return error .Unknown ) else null ;
802802 },
803- else = > @compileError (std .fmt .comptimePrint ("unhandled column type: {s}" , .{@typeName (field . type )})),
803+ else = > @compileError (std .fmt .comptimePrint ("unhandled column type: {s}" , .{@typeName (field_type )})),
804804 }
805805 }
806806
0 commit comments