v / vlib / orm / orm_option_subselect_test.v
49 lines · 41 sloc · 715 bytes · 7078a2e1852eedea76bb1a9e951da6ca76aa7e4d
Raw
1import db.sqlite
2
3fn test_main() {
4 db := sqlite.connect(':memory:')!
5
6 sql db {
7 create table Commit
8 create table Measurement
9 }!
10
11 c := Commit{
12 commit_hash: 'hash'
13 }
14 sql db {
15 insert c into Commit
16 }!
17
18 c2 := sql db {
19 select from Commit
20 }!
21 assert c2[0].v_self_default == none
22
23 c3 := Commit{
24 commit_hash: 'hash1'
25 v_self_default: Measurement{
26 id: 123
27 }
28 }
29 sql db {
30 insert c3 into Commit
31 }!
32
33 c4 := sql db {
34 select from Commit
35 }!
36 assert c4[0].v_self_default == none
37 assert c4[1].v_self_default != none
38}
39
40@[table: 'commits']
41struct Commit {
42 commit_hash string @[primary]
43 v_self_default ?Measurement
44}
45
46@[table: 'measurements']
47struct Measurement {
48 id int @[primary; serial]
49}
50