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 {
|
for attr in field.attrs {
|
||||||
match attr.name {
|
match attr.name {
|
||||||
|
'sql' {
|
||||||
|
// [sql:'-']
|
||||||
|
if attr.arg == '-' {
|
||||||
|
is_skip = true
|
||||||
|
}
|
||||||
|
}
|
||||||
'primary' {
|
'primary' {
|
||||||
primary = field.name
|
primary = field.name
|
||||||
}
|
}
|
||||||
@ -470,13 +476,13 @@ pub fn orm_table_gen(table string, q string, defaults bool, def_unique_len int,
|
|||||||
}
|
}
|
||||||
'sql_type' {
|
'sql_type' {
|
||||||
if attr.kind != .string {
|
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
|
ctyp = attr.arg
|
||||||
}
|
}
|
||||||
'default' {
|
'default' {
|
||||||
if attr.kind != .string {
|
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 == '' {
|
if default_val == '' {
|
||||||
default_val = attr.arg
|
default_val = attr.arg
|
||||||
|
@ -23,6 +23,7 @@ struct User {
|
|||||||
name string [sql: 'username']
|
name string [sql: 'username']
|
||||||
is_customer bool
|
is_customer bool
|
||||||
skipped_string string [skip]
|
skipped_string string [skip]
|
||||||
|
skipped_string2 string [sql: '-']
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Foo {
|
struct Foo {
|
||||||
@ -59,6 +60,8 @@ fn test_use_struct_field_as_limit() {
|
|||||||
}!
|
}!
|
||||||
|
|
||||||
assert users.len == 1
|
assert users.len == 1
|
||||||
|
assert users[0].skipped_string == ''
|
||||||
|
assert users[0].skipped_string2 == ''
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_orm() {
|
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 {
|
match attr.name {
|
||||||
'json' {
|
'json' {
|
||||||
if attr.arg == '-' {
|
if attr.arg == '-' {
|
||||||
|
// [json:'-']
|
||||||
is_skip = true
|
is_skip = true
|
||||||
} else {
|
} else {
|
||||||
name = attr.arg
|
name = attr.arg
|
||||||
|
Loading…
Reference in New Issue
Block a user