1
0
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:
walking devel 2023-02-15 17:47:35 +00:00 committed by GitHub
parent f5423ed26b
commit 5d4c9dc9fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 0 deletions

View File

@ -34,6 +34,33 @@ struct TestTime {
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() {
db := sqlite.connect(':memory:') or { panic(err) }

View File

@ -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() {
return
}
} else if expr is ast.SelectorExpr {
if expr.typ.is_int() {
return
}
} else if expr is ast.CallExpr {
if expr.return_type == 0 {
return