mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
orm: fix time struct in sql stmt (#12298)
This commit is contained in:
parent
5e4594a121
commit
d33f7d12f7
@ -5,11 +5,12 @@ import time
|
||||
import sqlite
|
||||
|
||||
struct Module {
|
||||
id int [primary; sql: serial]
|
||||
id int [primary; sql: serial]
|
||||
name string
|
||||
nr_downloads int
|
||||
test_id u64
|
||||
user User
|
||||
created time.Time
|
||||
}
|
||||
|
||||
[table: 'userlist']
|
||||
@ -330,4 +331,16 @@ fn test_orm_sqlite() {
|
||||
}
|
||||
|
||||
assert test_id_mod.test_id == 11
|
||||
|
||||
t := time.now()
|
||||
sql db {
|
||||
update Module set created = t where id == 1
|
||||
}
|
||||
updated_time_mod := sql db {
|
||||
select from Module where id == 1
|
||||
}
|
||||
// NB: usually updated_time_mod.created != t, because t has
|
||||
// its microseconds set, while the value retrieved from the DB
|
||||
// has them zeroed, because the db field resolution is seconds.
|
||||
assert updated_time_mod.created.format_ss() == t.format_ss()
|
||||
}
|
||||
|
@ -7893,7 +7893,7 @@ fn (mut c Checker) fetch_field_name(field ast.StructField) string {
|
||||
}
|
||||
}
|
||||
sym := c.table.get_type_symbol(field.typ)
|
||||
if sym.kind == .struct_ {
|
||||
if sym.kind == .struct_ && sym.name != 'time.Time' {
|
||||
name = '${name}_id'
|
||||
}
|
||||
return name
|
||||
|
Loading…
Reference in New Issue
Block a user