@@ -387,68 +387,67 @@ fn table_from_struct[T]() Table {
387387fn struct_meta [T]() []TableField {
388388 mut meta := []TableField{}
389389 $for field in T.fields {
390- if field.is_embed {
391- continue
392- }
393- mut attrs := []VAttribute{}
394- mut is_skip := false
395- for attr in field.attrs {
396- f := attr.split_any (':' )
397- if f.len == 1 {
398- ff := f[0 ].trim_space ()
399- if ff == 'skip' {
400- is_skip = true
401- }
402- attrs << VAttribute{
403- name: ff
404- }
405- continue
406- }
407- if f.len == 2 {
408- ff := f[1 ].trim_space ()
409- if f[0 ].trim_space () == 'sql' && ff == '-' {
410- is_skip = true
411- }
412- mut kind := AttributeKind.plain
413- if ff == 'true' || ff == 'false' {
414- kind = .bool
415- } else if ff.starts_with ('if ' ) {
416- kind = .comptime_define
417- } else if (ff.starts_with ("'" ) && ff.ends_with ("'" ))
418- || (ff.starts_with ('"' ) && ff.ends_with ('"' )) {
419- kind = .string
420- } else if ff.contains_only ('0123456789' ) {
421- kind = .number
422- } else if ff ! in ['serial' , 'i8' , 'i16' , 'int' , 'i64' , 'u8' , 'u16' , 'u32' , 'u64' ,
423- 'f32' , 'f64' , 'bool' , 'string' ] {
424- // @[sql: data_type] need kind = .plain
425- // @[sql: column_name] need kind = .string
426- kind = .string
390+ if ! field.is_embed {
391+ mut attrs := []VAttribute{}
392+ mut is_skip := false
393+ for attr in field.attrs {
394+ f := attr.split_any (':' )
395+ if f.len == 1 {
396+ ff := f[0 ].trim_space ()
397+ if ff == 'skip' {
398+ is_skip = true
399+ }
400+ attrs << VAttribute{
401+ name: ff
402+ }
403+ continue
427404 }
428- attrs << VAttribute{
429- name: f[0 ].trim_space ()
430- has_arg: true
431- arg: ff
432- kind: kind
405+ if f.len == 2 {
406+ ff := f[1 ].trim_space ()
407+ if f[0 ].trim_space () == 'sql' && ff == '-' {
408+ is_skip = true
409+ }
410+ mut kind := AttributeKind.plain
411+ if ff == 'true' || ff == 'false' {
412+ kind = .bool
413+ } else if ff.starts_with ('if ' ) {
414+ kind = .comptime_define
415+ } else if (ff.starts_with ("'" ) && ff.ends_with ("'" ))
416+ || (ff.starts_with ('"' ) && ff.ends_with ('"' )) {
417+ kind = .string
418+ } else if ff.contains_only ('0123456789' ) {
419+ kind = .number
420+ } else if ff ! in ['serial' , 'i8' , 'i16' , 'int' , 'i64' , 'u8' , 'u16' , 'u32' ,
421+ 'u64' , 'f32' , 'f64' , 'bool' , 'string' ] {
422+ // @[sql: data_type] need kind = .plain
423+ // @[sql: column_name] need kind = .string
424+ kind = .string
425+ }
426+ attrs << VAttribute{
427+ name: f[0 ].trim_space ()
428+ has_arg: true
429+ arg: ff
430+ kind: kind
431+ }
433432 }
434433 }
435- }
436434
437- mut field_type := field.typ
438- if typeof (field).name.contains ('time.Time' ) {
439- field_type = time_
440- } else if field.is_struct {
441- field_type = type_idx['int' ]
442- } else if field.is_enum {
443- field_type = enum_
444- }
435+ mut field_type := field.typ
436+ if typeof (field).name.contains ('time.Time' ) {
437+ field_type = time_
438+ } else if field.is_struct {
439+ field_type = type_idx['int' ]
440+ } else if field.is_enum {
441+ field_type = enum_
442+ }
445443
446- if ! is_skip {
447- meta << TableField{
448- name: field.name
449- typ: field_type
450- nullable: field.is_option
451- attrs: attrs
444+ if ! is_skip {
445+ meta << TableField{
446+ name: field.name
447+ typ: field_type
448+ nullable: field.is_option
449+ attrs: attrs
450+ }
452451 }
453452 }
454453 }
0 commit comments