v/vlib/v/tests/orm_sub_struct_test.v

35 lines
484 B
V
Raw Normal View History

2021-02-04 20:28:33 +01:00
import sqlite
struct Upper {
id int [primary; sql: serial]
2021-02-04 20:28:33 +01:00
sub SubStruct
}
struct SubStruct {
id int [primary; sql: serial]
2021-02-04 20:28:33 +01:00
name string
}
fn test_orm_sub_structs() {
db := sqlite.connect(':memory:') or { panic(err) }
sql db {
create table Upper
}
2021-02-04 20:28:33 +01:00
upper_1 := Upper{
sub: SubStruct{
name: 'test123'
}
}
sql db {
insert upper_1 into Upper
}
upper_s := sql db {
select from Upper where id == 1
}
assert upper_s.sub.name == upper_1.sub.name
}