orm: more fixes and tests

pull/5404/head
Alexander Medvednikov 2020-06-17 14:29:44 +02:00
parent 6066414afa
commit 325a7c7ec5
3 changed files with 23 additions and 2 deletions

View File

@ -743,16 +743,19 @@ fn test_double_quote_inter() {
}
fn test_string_map() {
$if windows {
return // TODO
}
a := 'Hello'.map(fn (b byte) byte {
return b + 1
})
})
assert a == 'Ifmmp'
assert 'foo'.map(foo) == r'\ee'
}
fn foo(b byte) byte {
return b - 10
return b - 10
}
fn test_split_into_lines() {

View File

@ -66,6 +66,20 @@ fn test_orm_sqlite() {
assert users[0].name == 'Sam'
assert users[1].name == 'Peter'
assert users[1].age == 31
//
users2 := sql db {
select from User where id < 0
}
println(users2)
assert users2.len == 0
//
users3 := sql db {
select from User where age == 29 || age == 31
}
println(users3)
assert users3.len == 2
assert users3[0].age == 29
assert users3[1].age == 31
}

View File

@ -119,7 +119,11 @@ fn (mut g Gen) expr_to_sql(expr ast.Expr) {
match it.op {
.eq { g.write(' = ') }
.gt { g.write(' > ') }
.lt { g.write(' < ') }
.ge { g.write(' >= ') }
.le { g.write(' <= ') }
.and { g.write(' and ') }
.logical_or { g.write(' or ') }
else {}
}
g.expr_to_sql(it.right)