mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
orm: enforce that queries always return a Result, a query-resulting array can be used as a V array in place. (#17871)
This commit is contained in:
@ -25,10 +25,10 @@ struct Account {
|
||||
id int [primary; sql: serial]
|
||||
}
|
||||
|
||||
pub fn insert_parent(db sqlite.DB, mut parent Parent) {
|
||||
pub fn insert_parent(db sqlite.DB, mut parent Parent) ! {
|
||||
sql db {
|
||||
insert parent into Parent
|
||||
}
|
||||
}!
|
||||
}
|
||||
|
||||
fn test_insert_empty_object() {
|
||||
@ -39,11 +39,11 @@ fn test_insert_empty_object() {
|
||||
sql db {
|
||||
create table Account
|
||||
insert account into Account
|
||||
}
|
||||
}!
|
||||
|
||||
accounts := sql db {
|
||||
select from Account
|
||||
}
|
||||
}!
|
||||
|
||||
assert accounts.len == 1
|
||||
}
|
||||
@ -55,17 +55,17 @@ fn test_orm_insert_mut_object() {
|
||||
create table Parent
|
||||
create table Child
|
||||
create table Note
|
||||
}
|
||||
}!
|
||||
|
||||
mut parent := Parent{
|
||||
name: 'test'
|
||||
}
|
||||
|
||||
insert_parent(db, mut parent)
|
||||
insert_parent(db, mut parent)!
|
||||
|
||||
parents := sql db {
|
||||
select from Parent
|
||||
}
|
||||
}!
|
||||
|
||||
assert parents.len == 1
|
||||
}
|
||||
@ -77,7 +77,7 @@ fn test_orm_insert_with_multiple_child_elements() {
|
||||
create table Parent
|
||||
create table Child
|
||||
create table Note
|
||||
}
|
||||
}!
|
||||
|
||||
new_parent := Parent{
|
||||
name: 'test'
|
||||
@ -104,11 +104,11 @@ fn test_orm_insert_with_multiple_child_elements() {
|
||||
|
||||
sql db {
|
||||
insert new_parent into Parent
|
||||
}
|
||||
}!
|
||||
|
||||
parents := sql db {
|
||||
select from Parent where id == 1
|
||||
}
|
||||
}!
|
||||
|
||||
parent := parents.first()
|
||||
assert parent.children.len == new_parent.children.len
|
||||
@ -116,12 +116,12 @@ fn test_orm_insert_with_multiple_child_elements() {
|
||||
|
||||
children_count := sql db {
|
||||
select count from Child
|
||||
}
|
||||
}!
|
||||
assert children_count == new_parent.children.len
|
||||
|
||||
note_count := sql db {
|
||||
select count from Note
|
||||
}
|
||||
}!
|
||||
assert note_count == new_parent.notes.len
|
||||
|
||||
assert parent.children[0].name == 'Lisa'
|
||||
|
Reference in New Issue
Block a user