hood icon indicating copy to clipboard operation
hood copied to clipboard

AfterGet / AfterSelect

Open robfig opened this issue 11 years ago • 2 comments

How do you feel about adding a hook that runs after loading an entity? I use this feature (in Gorp) presently for two things:

  1. Eagerly loading relations
  2. 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.

robfig avatar Feb 02 '13 16:02 robfig

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).

eaigner avatar Feb 02 '13 17:02 eaigner

ad 1) should be trivial to add

eaigner avatar Feb 02 '13 17:02 eaigner