hood
hood copied to clipboard
AfterGet / AfterSelect
How do you feel about adding a hook that runs after loading an entity? I use this feature (in Gorp) presently for two things:
- Eagerly loading relations
- Setting Go properties that do not map directly to a SQL data type -- for example, time.Time does not work with sqlite3 -- to work around that, in BeforeSave I set a TimeStr string field on the model, and in AfterGet I parse that property back into the time.Time field.
Although, it looks like there is no way to issue queries from the hook, so use case (1) would not apply anyway.
ad 2) you can map Go to DB specific types with the dialect interface, no hooks required
PS: there's actually a sqlite dialect implementation, it's just not on the main branch since some methods are missing, and need to be implemented with workarounds (sqlite doesn't support all sql commands).
ad 1) should be trivial to add