I'd like to insert any type of JSON directly into BigQuery, but haven't found any good way of doing this? All ways assume I have a well defined struct that I insert. It seems it was possible with the old deprecated api but not with the new "cloud.google.com/go/bigquery" package.
I'd like to have /api/table_name/insert be able to take any type of json and insert it into BigQuery as both the client and server knows the schema the endpoint should just forward it.
Thanks
seems like this was replaced with ValueSaver which you can implement like:
type genericRecord map[string]bigquery.Value
func (rec genericRecord) Save() (map[string]bigquery.Value, string, error) {
insertID := uuid.New().String()
return rec, insertID, nil
}
var data []*genericRecord
json.Unmarshal(<YOUR JSON BYTE>, &data)
ctx := context.Background()
client, err := bigquery.NewClient(ctx, <YOUR PROJECT ID>)
ins := client.Dataset(<DATASET>).Table(<TABLE>).Inserter()
ins.Put(ctx, data)