2021-02-04 20:28:33 +01:00
|
|
|
import sqlite
|
|
|
|
|
|
|
|
struct Upper {
|
2021-04-15 09:53:43 +02:00
|
|
|
id int [primary; sql: serial]
|
2021-02-04 20:28:33 +01:00
|
|
|
sub SubStruct
|
|
|
|
}
|
|
|
|
|
|
|
|
struct SubStruct {
|
2021-04-15 09:53:43 +02:00
|
|
|
id int [primary; sql: serial]
|
2021-02-04 20:28:33 +01:00
|
|
|
name string
|
|
|
|
}
|
|
|
|
|
|
|
|
fn test_orm_sub_structs() {
|
2021-03-01 00:18:14 +01:00
|
|
|
db := sqlite.connect(':memory:') or { panic(err) }
|
2021-04-15 09:53:43 +02:00
|
|
|
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
|
2021-02-28 21:20:21 +01:00
|
|
|
}
|