mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: allow using struct field as ORM limit and offset. (#17330)
This commit is contained in:
parent
f5423ed26b
commit
5d4c9dc9fc
@ -34,6 +34,33 @@ struct TestTime {
|
|||||||
create time.Time
|
create time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn test_use_struct_field_as_limit() {
|
||||||
|
db := sqlite.connect(':memory:') or { panic(err) }
|
||||||
|
|
||||||
|
sql db {
|
||||||
|
create table User
|
||||||
|
}
|
||||||
|
|
||||||
|
foo := Foo{
|
||||||
|
age: 10
|
||||||
|
}
|
||||||
|
|
||||||
|
sam := User{
|
||||||
|
age: 29
|
||||||
|
name: 'Sam'
|
||||||
|
}
|
||||||
|
|
||||||
|
sql db {
|
||||||
|
insert sam into User
|
||||||
|
}
|
||||||
|
|
||||||
|
users := sql db {
|
||||||
|
select from User limit foo.age
|
||||||
|
}
|
||||||
|
|
||||||
|
assert users.len == 1
|
||||||
|
}
|
||||||
|
|
||||||
fn test_orm() {
|
fn test_orm() {
|
||||||
db := sqlite.connect(':memory:') or { panic(err) }
|
db := sqlite.connect(':memory:') or { panic(err) }
|
||||||
|
|
||||||
|
@ -348,6 +348,10 @@ fn (mut c Checker) check_sql_expr_type_is_int(expr &ast.Expr, sql_keyword string
|
|||||||
if expr.obj.typ.is_int() {
|
if expr.obj.typ.is_int() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
} else if expr is ast.SelectorExpr {
|
||||||
|
if expr.typ.is_int() {
|
||||||
|
return
|
||||||
|
}
|
||||||
} else if expr is ast.CallExpr {
|
} else if expr is ast.CallExpr {
|
||||||
if expr.return_type == 0 {
|
if expr.return_type == 0 {
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user