-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
orm: fix code generation for an option time.Time field (vlang#20031)
- Loading branch information
Showing
3 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters