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:
parent
b9f5cc830b
commit
9f118ba3f1
@ -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
|
||||
|
@ -18,11 +18,12 @@ struct Module {
|
||||
|
||||
[table: 'userlist']
|
||||
struct User {
|
||||
id int [primary; sql: serial]
|
||||
age int
|
||||
name string [sql: 'username']
|
||||
is_customer bool
|
||||
skipped_string string [skip]
|
||||
id int [primary; sql: serial]
|
||||
age int
|
||||
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() {
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user