commit | 4537b45d2611ce480abfb5d186b59e7258ec872c | [log] [tgz] |
---|---|---|
author | Knut Olav Løite <koloite@gmail.com> | Tue Oct 19 09:44:12 2021 +0200 |
committer | GitHub <noreply@github.com> | Tue Oct 19 07:44:12 2021 +0000 |
tree | ba5e7ef4c84d179875e30578a637c886d4513ca0 | |
parent | 44bc953a426874e7c4cc49c91af0903b83f90477 [diff] |
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.
Go packages for Google Cloud Platform services.
import "cloud.google.com/go"
To install the packages on your system, do not clone the repo. Instead:
Change to your project directory:
cd /my/cloud/project
Get the package you want to use. Some products have their own module, so it's best to go get
the package(s) you want to use:
$ go get cloud.google.com/go/firestore # Replace with the package you want to use.
NOTE: Some of these packages are under development, and may occasionally make backwards-incompatible changes.
For an updated list of all of our released APIs please see our reference docs.
We currently support Go versions 1.11 and newer.
By default, each API will use Google Application Default Credentials for authorization credentials used in calling the API endpoints. This will allow your application to run in many environments without requiring explicit configuration.
client, err := storage.NewClient(ctx)
To authorize using a JSON key file, pass option.WithCredentialsFile
to the NewClient
function of the desired package. For example:
client, err := storage.NewClient(ctx, option.WithCredentialsFile("path/to/keyfile.json"))
You can exert more control over authorization by using the golang.org/x/oauth2
package to create an oauth2.TokenSource
. Then pass option.WithTokenSource
to the NewClient
function: snip:# (auth-ts)
tokenSource := ...
client, err := storage.NewClient(ctx, option.WithTokenSource(tokenSource))
Contributions are welcome. Please, see the CONTRIBUTING document for details.
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. See Contributor Code of Conduct for more information.