test-cleancode: add vlib/orm (#7577)

pull/7582/head
Lukas Neubert 2020-12-26 13:40:22 +01:00 committed by GitHub
parent 693e5137eb
commit 6969300f8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 27 deletions

View File

@ -24,6 +24,7 @@ const (
'vlib/builtin/array_test.v', 'vlib/builtin/array_test.v',
'vlib/builtin/map.v', 'vlib/builtin/map.v',
'vlib/math/bits/bits.v', 'vlib/math/bits/bits.v',
'vlib/orm/',
'vlib/term/colors.v', 'vlib/term/colors.v',
'vlib/term/term.v', 'vlib/term/term.v',
'vlib/v/ast/', 'vlib/v/ast/',

View File

@ -23,11 +23,9 @@ struct Foo {
fn test_orm_sqlite() { fn test_orm_sqlite() {
db := sqlite.connect(':memory:') or { panic(err) } db := sqlite.connect(':memory:') or { panic(err) }
db.exec("drop table if exists User") db.exec('drop table if exists User')
db.exec("create table User (id integer primary key, age int default 0, name text default '', is_customer int default 0);") db.exec("create table User (id integer primary key, age int default 0, name text default '', is_customer int default 0);")
name := 'Peter' name := 'Peter'
db.exec("insert into User (name, age) values ('Sam', 29)") db.exec("insert into User (name, age) values ('Sam', 29)")
db.exec("insert into User (name, age) values ('Peter', 31)") db.exec("insert into User (name, age) values ('Peter', 31)")
db.exec("insert into User (name, age, is_customer) values ('Kate', 30, 1)") db.exec("insert into User (name, age, is_customer) values ('Kate', 30, 1)")
@ -99,8 +97,10 @@ fn test_orm_sqlite() {
assert users3[0].age == 29 assert users3[0].age == 29
assert users3[1].age == 31 assert users3[1].age == 31
// //
new_user := User{
new_user := User{name:'New user' age:30} name: 'New user'
age: 30
}
sql db { sql db {
insert new_user into User insert new_user into User
} }
@ -197,23 +197,18 @@ fn test_orm_sqlite() {
} }
assert z.len == 2 assert z.len == 2
assert z[0].id == 3 assert z[0].id == 3
oldest := sql db { oldest := sql db {
select from User order by age desc limit 1 select from User order by age desc limit 1
} }
assert oldest.age == 34 assert oldest.age == 34
offs := 1 offs := 1
second_oldest := sql db { second_oldest := sql db {
select from User order by age desc limit 1 offset offs select from User order by age desc limit 1 offset offs
} }
assert second_oldest.age == 31 assert second_oldest.age == 31
sql db { sql db {
delete from User where age == 34 delete from User where age == 34
} }
updated_oldest := sql db { updated_oldest := sql db {
select from User order by age desc limit 1 select from User order by age desc limit 1
} }
@ -244,7 +239,6 @@ fn test_orm_pg() {
println(mod) println(mod)
} }
*/ */
/* /*
mod := db.retrieve<Module>(1) mod := db.retrieve<Module>(1)
mod := db.select from Module where id = 1 mod := db.select from Module where id = 1