1
0
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:
walking devel
2023-04-04 05:23:06 +00:00
committed by GitHub
parent 9addede0ea
commit 8452644ec3
67 changed files with 479 additions and 354 deletions

View File

@@ -101,7 +101,7 @@ fn test_sqlite_orm() {
sql db {
create table TestCustomSqlType
}
}!
mut result_custom_sql, mut exec_custom_code := db.exec('
pragma table_info(TestCustomSqlType);
@@ -119,14 +119,14 @@ fn test_sqlite_orm() {
sql db {
drop table TestCustomSqlType
}
}!
/** test default attribute
*/
sql db {
create table TestDefaultAtribute
}
}!
mut result_default_sql, mut code := db.exec('
pragma table_info(TestDefaultAtribute);
@@ -147,11 +147,11 @@ fn test_sqlite_orm() {
sql db {
insert test_default_atribute into TestDefaultAtribute
}
}!
test_default_atributes := sql db {
select from TestDefaultAtribute limit 1
}
}!
result_test_default_atribute := test_default_atributes.first()
assert result_test_default_atribute.name == 'Hitalo'
@@ -164,7 +164,7 @@ fn test_sqlite_orm() {
sql db {
drop table TestDefaultAtribute
}
}!
}
fn test_get_affected_rows_count() {
@@ -204,26 +204,26 @@ fn test_get_affected_rows_count() {
all := sql db {
select from EntityToTest
}
}!
assert 1 == all.len
sql db {
update EntityToTest set smth = '2' where id == 1
}
}!
assert db.get_affected_rows_count() == 1
sql db {
update EntityToTest set smth = '2' where id == 2
}
}!
assert db.get_affected_rows_count() == 0
sql db {
delete from EntityToTest where id == 2
}
}!
assert db.get_affected_rows_count() == 0
sql db {
delete from EntityToTest where id == 1
}
}!
assert db.get_affected_rows_count() == 1
}

View File

@@ -19,10 +19,10 @@ fn (back Host) get_users() []User {
return []
}
fn create_host(db Connection) Host {
fn create_host(db Connection) !Host {
sql db {
create table User
}
}!
return Host{
db: db
@@ -87,6 +87,6 @@ fn test_can_access_sqlite_result_consts() {
}
fn test_alias_db() {
create_host(sqlite.connect(':memory:')!)
create_host(sqlite.connect(':memory:')!)!
assert true
}