Skip to content

Commit 1ba1f99

Browse files
authored
orm: declare missing functions to handle literal types (#16627)
1 parent b6c2aab commit 1ba1f99

3 files changed

Lines changed: 49 additions & 0 deletions

File tree

cmd/tools/vtest-self.v

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ const (
137137
'vlib/crypto/rand/crypto_rand_read_test.v',
138138
'vlib/net/smtp/smtp_test.v',
139139
'vlib/v/tests/websocket_logger_interface_should_compile_test.v',
140+
'vlib/v/tests/fn_literal_type_test.v',
140141
]
141142
skip_with_fsanitize_address = [
142143
'vlib/net/websocket/websocket_test.v',
@@ -189,6 +190,7 @@ const (
189190
'vlib/builtin/js/array_test.js.v',
190191
'vlib/net/smtp/smtp_test.v',
191192
'vlib/v/tests/websocket_logger_interface_should_compile_test.v',
193+
'vlib/v/tests/fn_literal_type_test.v',
192194
]
193195
skip_on_linux = [
194196
'do_not_remove',
@@ -224,6 +226,7 @@ const (
224226
'vlib/sync/many_times_test.v',
225227
'vlib/sync/once_test.v',
226228
'vlib/v/tests/websocket_logger_interface_should_compile_test.v',
229+
'vlib/v/tests/fn_literal_type_test.v',
227230
]
228231
skip_on_non_windows = [
229232
'do_not_remove',

vlib/orm/orm.v

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,16 @@ pub fn int_to_primitive(b int) Primitive {
562562
return Primitive(b)
563563
}
564564

565+
// int_literal_to_primitive handles int literal value
566+
pub fn int_literal_to_primitive(b int) Primitive {
567+
return Primitive(b)
568+
}
569+
570+
// float_literal_to_primitive handles float literal value
571+
pub fn float_literal_to_primitive(b f64) Primitive {
572+
return Primitive(b)
573+
}
574+
565575
pub fn i64_to_primitive(b i64) Primitive {
566576
return Primitive(b)
567577
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import sqlite
2+
3+
[table: 'Users']
4+
struct User {
5+
id int [primary; sql: serial]
6+
name string
7+
}
8+
9+
const (
10+
const_users_offset = 1
11+
const_users_offset2 = 1
12+
)
13+
14+
fn test_orm() {
15+
db := sqlite.connect(':memory:') or { panic(err) }
16+
17+
upper_1 := User{
18+
name: 'Test'
19+
}
20+
21+
upper_2 := User{
22+
name: 'Test2'
23+
}
24+
25+
sql db {
26+
create table User
27+
insert upper_1 into User
28+
insert upper_2 into User
29+
} or { panic(err) }
30+
31+
result := sql db {
32+
select from User limit const_users_offset2
33+
} or { panic(err) }
34+
35+
assert result[0].name == 'Test'
36+
}

0 commit comments

Comments
 (0)