@@ -20,6 +20,7 @@ import (
20
20
21
21
"golang.org/x/net/context"
22
22
23
+ "cloud.google.com/go/internal/optional"
23
24
bq "google.golang.org/api/bigquery/v2"
24
25
)
25
26
@@ -245,6 +246,8 @@ type TableMetadataPatch struct {
245
246
246
247
// Patch returns a *TableMetadataPatch, which can be used to modify specific Table metadata fields.
247
248
// In order to apply the changes, the TableMetadataPatch's Apply method must be called.
249
+ //
250
+ // Deprecated: use Table.Update instead.
248
251
func (t * Table ) Patch () * TableMetadataPatch {
249
252
return & TableMetadataPatch {
250
253
s : t .c .service ,
@@ -255,22 +258,53 @@ func (t *Table) Patch() *TableMetadataPatch {
255
258
}
256
259
257
260
// Description sets the table description.
261
+ //
262
+ // Deprecated: use Table.Update instead.
258
263
func (p * TableMetadataPatch ) Description (desc string ) {
259
264
p .conf .Description = & desc
260
265
}
261
266
262
267
// Name sets the table name.
268
+ //
269
+ // Deprecated: use Table.Update instead.
263
270
func (p * TableMetadataPatch ) Name (name string ) {
264
271
p .conf .Name = & name
265
272
}
266
273
267
- // TODO(mcgreevy): support patching the schema.
268
-
269
274
// Apply applies the patch operation.
275
+ //
276
+ // Deprecated: use Table.Update instead.
270
277
func (p * TableMetadataPatch ) Apply (ctx context.Context ) (* TableMetadata , error ) {
271
278
return p .s .patchTable (ctx , p .projectID , p .datasetID , p .tableID , & p .conf )
272
279
}
273
280
281
+ // Update modifies specific Table metadata fields.
282
+ func (t * Table ) Update (ctx context.Context , tm TableMetadataToUpdate ) (* TableMetadata , error ) {
283
+ var conf patchTableConf
284
+ if tm .Description != nil {
285
+ s := optional .ToString (tm .Description )
286
+ conf .Description = & s
287
+ }
288
+ if tm .Name != nil {
289
+ s := optional .ToString (tm .Name )
290
+ conf .Name = & s
291
+ }
292
+ return t .c .service .patchTable (ctx , t .ProjectID , t .DatasetID , t .TableID , & conf )
293
+ }
294
+
295
+ // TableMetadataToUpdate is used when updating a table's metadata.
296
+ // Only non-nil fields will be updated.
297
+ type TableMetadataToUpdate struct {
298
+ // Description is the user-friendly description of this table.
299
+ Description optional.String
300
+
301
+ // Name is the user-friendly name for this table.
302
+ Name optional.String
303
+
304
+ // TODO(jba): support updating the schema
305
+ // TODO(jba): support updating the view
306
+ }
307
+
274
308
// NewUploader returns an *Uploader that can be used to append rows to t.
275
309
func (t * Table ) NewUploader (opts ... UploadOption ) * Uploader {
276
310
uploader := & Uploader {t : t }
0 commit comments