1
0
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:
Louis Schmieder 2021-10-28 21:31:41 +02:00 committed by GitHub
parent 5e4594a121
commit d33f7d12f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View File

@ -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()
}

View File

@ -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