@@ -69,6 +69,7 @@ export type JobMetadataResponse = [JobMetadata];
6969export type RowMetadata = any ;
7070
7171export type InsertRowsOptions = bigquery . ITableDataInsertAllRequest & {
72+ createInsertId ?: boolean ;
7273 raw ?: boolean ;
7374 schema ?: string | { } ;
7475} ;
@@ -91,6 +92,11 @@ export type RowsCallback = PagedCallback<
9192 bigquery . ITableDataList | bigquery . ITable
9293> ;
9394
95+ export interface InsertRow {
96+ insertId ?: string ;
97+ json ?: bigquery . IJsonObject ;
98+ }
99+
94100export type TableRow = bigquery . ITableRow ;
95101export type TableRowField = bigquery . ITableCell ;
96102export type TableRowValue = string | TableRow ;
@@ -1726,6 +1732,8 @@ class Table extends common.ServiceObject {
17261732 *
17271733 * @param {object|object[] } rows The rows to insert into the table.
17281734 * @param {object } [options] Configuration object.
1735+ * @param {boolean } [options.createInsertId=true] Automatically insert a
1736+ * default row id when one is not provided.
17291737 * @param {boolean } [options.ignoreUnknownValues=false] Accept rows that contain
17301738 * values that do not match the schema. The unknown values are ignored.
17311739 * @param {boolean } [options.raw] If `true`, the `rows` argument is expected to
@@ -1861,19 +1869,23 @@ class Table extends common.ServiceObject {
18611869 throw new Error ( 'You must provide at least 1 row to be inserted.' ) ;
18621870 }
18631871
1864- const json = extend ( true , { } , options , {
1865- rows,
1866- } ) ;
1872+ const json = extend ( true , { } , options , { rows} ) ;
18671873
18681874 if ( ! options . raw ) {
18691875 json . rows = rows . map ( ( row : RowMetadata ) => {
1870- return {
1871- insertId : uuid . v4 ( ) ,
1872- json : Table . encodeValue_ ( row ) ,
1876+ const encoded : InsertRow = {
1877+ json : Table . encodeValue_ ( row ) ! ,
18731878 } ;
1879+
1880+ if ( options . createInsertId !== false ) {
1881+ encoded . insertId = uuid . v4 ( ) ;
1882+ }
1883+
1884+ return encoded ;
18741885 } ) ;
18751886 }
18761887
1888+ delete json . createInsertId ;
18771889 delete json . raw ;
18781890
18791891 let schema : string | { } ;
0 commit comments