mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
orm: fix code generation for an option time.Time field (#20031)
This commit is contained in:
parent
dc3ea0f87f
commit
00b1ce5760
3 changed files with 59 additions and 1 deletions
54
vlib/orm/orm_option_time_test.v
Normal file
54
vlib/orm/orm_option_time_test.v
Normal file
|
@ -0,0 +1,54 @@
|
|||
import db.sqlite
|
||||
import time
|
||||
|
||||
@[table: 'foos']
|
||||
struct Foo {
|
||||
id int @[primary; sql: serial]
|
||||
name string
|
||||
created_at time.Time @[default: 'CURRENT_TIME']
|
||||
updated_at ?string @[sql_type: 'TIMESTAMP']
|
||||
deleted_at ?time.Time
|
||||
children []Child @[fkey: 'parent_id']
|
||||
}
|
||||
|
||||
struct Child {
|
||||
id int @[primary; sql: serial]
|
||||
parent_id int
|
||||
name string
|
||||
}
|
||||
|
||||
fn test_main() {
|
||||
mut db := sqlite.connect(':memory:') or { panic(err) }
|
||||
defer {
|
||||
db.close() or { panic(err) }
|
||||
}
|
||||
|
||||
sql db {
|
||||
create table Foo
|
||||
}!
|
||||
foo := Foo{
|
||||
name: 'abc'
|
||||
created_at: time.now()
|
||||
// updated_at defaults to none
|
||||
// deleted_at defaults to none
|
||||
children: [
|
||||
Child{
|
||||
name: 'abc'
|
||||
},
|
||||
Child{
|
||||
name: 'def'
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
sql db {
|
||||
insert foo into Foo
|
||||
}!
|
||||
|
||||
data := sql db {
|
||||
select from Foo
|
||||
}![0]
|
||||
assert data.id == 1
|
||||
assert data.updated_at == none
|
||||
assert data.deleted_at == none
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue