-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(spanner): implement valuer and scanner interfaces (#4936)
### Valuer / Scanner Interfaces Adds implementations for the `driver.Valuer` and `sql.Scanner` interfaces for the Spanner Null* types. This makes it possible to use both the `spanner.Null*` types and the underlying native types in the Go sql driver. That is, both the following will then be supported: ```go var r spanner.NullNumeric rows.Scan(&r) ``` AND ```go var r big.Rat rows.Scan(&r) ``` It is not possible to implement this directly in the Go sql driver, as these types are defined in the `spanner` package. The interfaces are not implemented for the `spanner.NullJSON` type for two reasons: 1. `NullJSON` already has a field called `Value`, which makes it technically impossible to add a method called `Value()`. 2. The underlying value of `NullJSON` is of type `interface{}`, which means that it can be anything. This means that there is no relevant other type than `NullJSON` that a user can use when calling `sql.Row#Scan(dest ...interface{})` for a JSON column. ### Gorm Data Type Adds default data type mappings for the `spanner.Null*` types. That is; `NullInt64` is for example mapped by default to an `INT64` column. This allows structs that use `spanner.Null*` types for its fields to be used directly in Gorm migrations without the need to annotate them with the data type they should have in the database. This feature is implemented by adding the `func GormDataType() string` to each of the `spanner.Null*` types.
- Loading branch information
Showing
1 changed file
with
287 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters