Add an interface for type objects to control Ruby => SQL

Adds the ability to save custom types, which type cast to non-primitive
ruby objects.
Merge pull request #15307 from sgrif/sg-type-cast-for-write

Add an interface for type objects to control Ruby => SQL