-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
checker: ORM use of none/options and operations (added tests)
- Loading branch information
Showing
9 changed files
with
188 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
vlib/v/checker/tests/orm_fkey_attribute.vv:11:15: error: ORM: the `fkey` attribute must have an argument | ||
9 | id int [primary; sql: serial] | ||
10 | name string | ||
11 | user User [fkey] | ||
| ~~~~~~ | ||
12 | } | ||
13 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import db.sqlite | ||
|
||
struct User { | ||
id int [primary; sql: serial] | ||
} | ||
|
||
[table: foo] | ||
struct Foo { | ||
id int [primary; sql: serial] | ||
name string | ||
user User [fkey] | ||
} | ||
|
||
fn main() { | ||
db := sqlite.connect(':memory:')! | ||
sql db { | ||
create table Foo | ||
}! | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
vlib/v/checker/tests/orm_multidim_array.vv:12:5: error: ORM: multi-dimension array fields are not supported | ||
10 | id int [primary; sql: serial] | ||
11 | users []User [fkey: id] | ||
12 | bad [][]User [fkey: id] | ||
| ~~~~~~~~~~~~ | ||
13 | } | ||
14 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import db.sqlite | ||
|
||
[table: users] | ||
struct User { | ||
id int [pimary] | ||
} | ||
|
||
[table:foos] | ||
struct Foo { | ||
id int [primary; sql: serial] | ||
users []User [fkey: id] | ||
bad [][]User [fkey: id] | ||
} | ||
|
||
fn main() { | ||
db := sqlite.connect(':memory:')! | ||
sql db { | ||
create table Foo | ||
}! | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
vlib/v/checker/tests/orm_op_with_option_and_none.vv:11:30: warning: comparison with Option value probably isn't intended; use "is none" and "!is none" to select by NULL | ||
9 | db := sqlite.connect(':memory:')! | ||
10 | _ := sql db { | ||
11 | select from Foo where name == val | ||
| ~~ | ||
12 | }! | ||
13 | } | ||
vlib/v/checker/tests/orm_op_with_option_and_none.vv:25:30: warning: comparison with none probably isn't intended; use "is none" and "!is none" to select by NULL | ||
23 | | ||
24 | _ := sql db { | ||
25 | select from Foo where name == none | ||
| ~~ | ||
26 | }! | ||
27 | | ||
vlib/v/checker/tests/orm_op_with_option_and_none.vv:29:30: warning: comparison with none probably isn't intended; use "is none" and "!is none" to select by NULL | ||
27 | | ||
28 | _ := sql db { | ||
29 | select from Foo where name != none | ||
| ~~ | ||
30 | }! | ||
31 | | ||
vlib/v/checker/tests/orm_op_with_option_and_none.vv:33:30: warning: comparison with none probably isn't intended; use "is none" and "!is none" to select by NULL | ||
31 | | ||
32 | _ := sql db { | ||
33 | select from Foo where name < none | ||
| ^ | ||
34 | }! | ||
35 | | ||
vlib/v/checker/tests/orm_op_with_option_and_none.vv:37:30: warning: comparison with none probably isn't intended; use "is none" and "!is none" to select by NULL | ||
35 | | ||
36 | _ := sql db { | ||
37 | select from Foo where name > none | ||
| ^ | ||
38 | }! | ||
39 | | ||
vlib/v/checker/tests/orm_op_with_option_and_none.vv:41:30: warning: comparison with none probably isn't intended; use "is none" and "!is none" to select by NULL | ||
39 | | ||
40 | _ := sql db { | ||
41 | select from Foo where name <= none | ||
| ~~ | ||
42 | }! | ||
43 | | ||
vlib/v/checker/tests/orm_op_with_option_and_none.vv:45:30: warning: comparison with none probably isn't intended; use "is none" and "!is none" to select by NULL | ||
43 | | ||
44 | _ := sql db { | ||
45 | select from Foo where name >= none | ||
| ~~ | ||
46 | }! | ||
47 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import db.sqlite | ||
|
||
struct Foo { | ||
id u64 [primary; sql: serial] | ||
name ?string | ||
} | ||
|
||
fn bar(val ?string) ! { | ||
db := sqlite.connect(':memory:')! | ||
_ := sql db { | ||
select from Foo where name == val | ||
}! | ||
} | ||
|
||
fn main() { | ||
db := sqlite.connect(':memory:')! | ||
|
||
sql db { | ||
create table Foo | ||
}! | ||
|
||
bar(none) or {} | ||
|
||
_ := sql db { | ||
select from Foo where name == none | ||
}! | ||
|
||
_ := sql db { | ||
select from Foo where name != none | ||
}! | ||
|
||
_ := sql db { | ||
select from Foo where name < none | ||
}! | ||
|
||
_ := sql db { | ||
select from Foo where name > none | ||
}! | ||
|
||
_ := sql db { | ||
select from Foo where name <= none | ||
}! | ||
|
||
_ := sql db { | ||
select from Foo where name >= none | ||
}! | ||
|
||
_ := sql db { | ||
select from Foo where name is none | ||
}! | ||
|
||
_ := sql db { | ||
select from Foo where name !is none | ||
}! | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
vlib/v/checker/tests/orm_table_attributes.vv:3:1: error: ORM: table attribute must have an argument | ||
1 | import db.sqlite | ||
2 | | ||
3 | [table] | ||
| ~~~~~~~ | ||
4 | struct Foo { | ||
5 | id int [primary; sql: serial] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import db.sqlite | ||
|
||
[table] | ||
struct Foo { | ||
id int [primary; sql: serial] | ||
} | ||
|
||
fn main() { | ||
db := sqlite.connect(':memory:')! | ||
sql db { | ||
create table Foo | ||
}! | ||
} |