1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

orm: skip via the "-" attribute

This commit is contained in:
Alexander Medvednikov 2023-05-02 17:00:54 +02:00
parent b9f5cc830b
commit 9f118ba3f1
3 changed files with 17 additions and 7 deletions

View File

@ -446,6 +446,12 @@ pub fn orm_table_gen(table string, q string, defaults bool, def_unique_len int,
}
for attr in field.attrs {
match attr.name {
'sql' {
// [sql:'-']
if attr.arg == '-' {
is_skip = true
}
}
'primary' {
primary = field.name
}
@ -470,13 +476,13 @@ pub fn orm_table_gen(table string, q string, defaults bool, def_unique_len int,
}
'sql_type' {
if attr.kind != .string {
return error("sql_type attribute need be string. Try [sql_type: '${attr.arg}'] instead of [sql_type: ${attr.arg}]")
return error("sql_type attribute needs to be string. Try [sql_type: '${attr.arg}'] instead of [sql_type: ${attr.arg}]")
}
ctyp = attr.arg
}
'default' {
if attr.kind != .string {
return error("default attribute need be string. Try [default: '${attr.arg}'] instead of [default: ${attr.arg}]")
return error("default attribute needs to be string. Try [default: '${attr.arg}'] instead of [default: ${attr.arg}]")
}
if default_val == '' {
default_val = attr.arg

View File

@ -23,6 +23,7 @@ struct User {
name string [sql: 'username']
is_customer bool
skipped_string string [skip]
skipped_string2 string [sql: '-']
}
struct Foo {
@ -59,6 +60,8 @@ fn test_use_struct_field_as_limit() {
}!
assert users.len == 1
assert users[0].skipped_string == ''
assert users[0].skipped_string2 == ''
}
fn test_orm() {

View File

@ -528,6 +528,7 @@ fn (mut g Gen) gen_struct_enc_dec(utyp ast.Type, type_info ast.TypeInfo, styp st
match attr.name {
'json' {
if attr.arg == '-' {
// [json:'-']
is_skip = true
} else {
name = attr.arg