jsontype

package module
v0.0.0-...-cb19c07 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 10, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func InsertJsonSample1

func InsertJsonSample1(ctx context.Context) error

InsertJsonSample1 is interface{}突っ込んだら、雑にJsonにしてくれたりしないかなと思ったけど、ダメだった panic: spanner: code = "InvalidArgument", desc = "client doesn't support type *main.JsonBody"

Example

何も考えずにinterface{}を突っ込んでみて、無理ですと言われている図

package main

import (
	"context"
	"fmt"

	"github.com/sinmetal/til/spanner/jsontype"
)

func main() {
	ctx := context.Background()

	if err := jsontype.InsertJsonSample1(ctx); err != nil {
		fmt.Println(err.Error())
	}

}
Output:

spanner: code = "InvalidArgument", desc = "client doesn't support type *jsontype.JsonBody"

func InsertJsonSample2

func InsertJsonSample2(ctx context.Context) error

InsertJsonSample1 is interface{}突っ込んだら、雑にJsonにしてくれたりしないかなと思ったけど、ダメだった panic: spanner: code = "InvalidArgument", desc = "client doesn't support type *main.JsonBody"

Example

[]byteにjsonを突っ込んでみて、やっぱりダメですと言われる図

package main

import (
	"context"
	"fmt"

	"github.com/sinmetal/til/spanner/jsontype"
)

func main() {
	ctx := context.Background()

	if err := jsontype.InsertJsonSample2(ctx); err != nil {
		fmt.Println(err.Error())
	}

}
Output:

spanner: code = "FailedPrecondition", desc = "Invalid value for column Json in table JsonSample: Expected JSON."

func InsertJsonSample3

func InsertJsonSample3(ctx context.Context) error

InsertJsonSample1 is interface{}突っ込んだら、雑にJsonにしてくれたりしないかなと思ったけど、ダメだった panic: spanner: code = "InvalidArgument", desc = "client doesn't support type *main.JsonBody"

Example

spanner.NullJSONを使った図

package main

import (
	"context"
	"fmt"

	"github.com/sinmetal/til/spanner/jsontype"
)

func main() {
	ctx := context.Background()

	if err := jsontype.InsertJsonSample3(ctx); err != nil {
		fmt.Println(err.Error())
	}

}
Output:

jsontype.Entity{ID:"sample", Json:spanner.NullJSON{Value:map[string]interface {}{"Count":100, "Date":"2021-08-30T13:00:00Z", "ID":"helloJson"}, Valid:true}}

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL