cloudspannerecosystem / yo

yo is a command-line tool to generate Go code for Google Cloud Spanner.
MIT License
312 stars 52 forks source link

How to access custom-type-package name in templates? #49

Closed S-YOU closed 4 years ago

S-YOU commented 4 years ago

I would like to access custom-type-package name provided in command line. Use case is to separate model / repository layer, yo works out of the box, but this custom-type-package, I couldn't figure out how to access. Of course I could hard-code it since I know the name, but if there is way to access the custom-type-package name in templates that would be more flexible. Thanks.

kazegusuri commented 4 years ago

AFAIK no one use custom-type-package, custom-types-file is used instead for the purposes.

I see some applications in my company uses custom-types-file to generate repository layer by fully customizing templates. Though the current implementation of custom-types-file is very hacky and hard to maintain the behavior. So I think I will change it in the future. If you use the feature, please keep it in mind.

S-YOU commented 4 years ago

ok, I also noticed that you can use EncodeSpanner/DecodeSpanner features to convert between Go/Spanner types, .CustomType is not actually needed in my use case.

kazegusuri commented 4 years ago

Yes the recent version of google cloud go supports Encoder/Decoder, we can go a different way to customize models.