v / vlib / orm / orm_result_test.v
89 lines · 62 sloc · 1.19 KB · b99c3826ce9ab9391e4742d9d6896a3cfb9a8f3d
Raw
1// vtest retry: 3
2import db.sqlite
3
4struct Account {
5 id int @[primary; sql: serial]
6 name string
7}
8
9struct Note {
10 id int @[primary; sql: serial]
11 content string
12}
13
14fn test_catch_table_is_not_created() {
15 mut db := sqlite.connect(':memory:')!
16
17 mut is_inserted := true
18
19 account := Account{}
20
21 sql db {
22 insert account into Account
23 } or { is_inserted = false }
24
25 assert !is_inserted
26}
27
28fn test_catch_one_of_queries() {
29 mut db := sqlite.connect(':memory:')!
30
31 sql db {
32 create table Account
33 }!
34
35 account := Account{}
36
37 sql db {
38 insert account into Account
39 }!
40
41 mut are_updated := true
42
43 sql db {
44 update Account set name = 'test' where id == 1
45 update Note set content = 'test' where id == 1
46 } or { are_updated = false }
47
48 assert !are_updated
49}
50
51fn test_print_results() {
52 mut db := sqlite.connect(':memory:')!
53
54 sql db {
55 create table Account
56 }!
57
58 account := Account{}
59
60 sql db {
61 insert account into Account
62 }!
63
64 i := sql db {
65 insert account into Account
66 }!
67
68 println(i)
69
70 count := sql db {
71 select count from Account
72 }!
73
74 println(count)
75
76 user := sql db {
77 select from Account
78 }!.first()
79
80 println(user)
81
82 users := sql db {
83 select from Account
84 }!
85
86 println(users)
87
88 assert true
89}
90