skilld-labs / go-odoo

Golang wrapper for Odoo API
Apache License 2.0
86 stars 62 forks source link

What is the NilableType construct for? #14

Closed blaggacao closed 6 years ago

blaggacao commented 6 years ago

I cannot understand. I tried. Probably not hard enough, but I'm hitting the Wall..

jbguerraz commented 6 years ago

Hello David,

Glad to see you've got interest in that tool :)

The NilableType is indeed kinda tricky.

The main issue is Odoo will send a false if a field is not set; so a field of type int64 for instance won't be able to cope with such false value.

We could have decided to use only interface{} type and require go-odoo users to type their fields when they need to but instead we decided to go the strongly typed way (so one doesn't have to care much about fields types).

To do so we had to create a nilable structure which uses only interface{} typed fields (except for Booleans for which false isn't an issue) that is used for loading data from Odoo (https://github.com/skilld-labs/go-odoo/blob/1a704aa783362bf60d190ee4b6815faed265992e/api/client.go#L81 - https://github.com/skilld-labs/go-odoo/blob/1a704aa783362bf60d190ee4b6815faed265992e/api/client.go#L90) and a load method that would inspect the nilable variant of the object in order to create a properly typed one (https://github.com/skilld-labs/go-odoo/blob/c83e3b804cde2da2446df7c00726df18c66374c1/types/types.go#L39) that will then replace the struct the user passed to the Read / SearchRead methods (https://github.com/skilld-labs/go-odoo/blob/1a704aa783362bf60d190ee4b6815faed265992e/api/client.go#L85). All of that being transparent to the go-odoo user

Hope that helps :)

Thank you for your contrib efforts on other issues. We surely gonna adopt / contribute with you on those matters in a few (at the moment we're kinda busy).

blaggacao commented 6 years ago

Wow, could not have been clearer! Copy past to the wiki it! :wink:

jbguerraz commented 6 years ago

Done https://github.com/skilld-labs/go-odoo/wiki ;)