Custom datastore properties

35 views
Skip to first unread message

matthew...@workiva.com

unread,
Jul 2, 2014, 3:16:43 PM7/2/14
to google-ap...@googlegroups.com
I am trying to understand the recommended way to make custom datastore properties via the PropertyLoadSaver interface.  From what I can tell from reading the source for newStructPLS, you have to provide Load() and Save() on the upper level model struct, not on the property itself.  I've made a little go package that provides a JsonProperty map[string]interface{} which is saved into the datastore as a string and it works ok, but the usage is a little more verbose than I would like especially compared to Python.

https://github.com/matthewbelisle-wf/jsonproperty

My question for the go/datastore experts is - does that seem like a good way in general to make a custom property?  Or is there an easier/cleaner way to do it?

Matthew Zimmerman

unread,
Jul 2, 2014, 3:37:17 PM7/2/14
to matthew...@workiva.com, google-appengine-go
Generally I think the interface was provided to give a way to
save/load data that doesn't conform to the standard types given. It
also helps on types that compute data on load, like in their example.

func (x *CustomPropsExample) Load(c <-chan Property) error {
// Load I and J as usual.
if err := datastore.LoadStruct(x, c); err != nil {
return err
}
// Derive the Sum field.
x.Sum = x.I + x.J
return nil
}

I don't understand the use case from what you've provided and why you
wouldn't just make the json an embedded struct.
> --
> You received this message because you are subscribed to the Google Groups "google-appengine-go" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to google-appengin...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

matthew...@workiva.com

unread,
Jul 2, 2014, 3:42:46 PM7/2/14
to google-ap...@googlegroups.com, matthew...@workiva.com
The use case is that this one can store arbitrary data, whereas embedded structs have to have their fields/types known before hand.
> To unsubscribe from this group and stop receiving emails from it, send an email to google-appengine-go+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages