Showing 2 of 11 files from the diff.

@@ -24,7 +24,7 @@
Loading
24 24
import {common as p} from 'protobufjs';
25 25
import * as streamEvents from 'stream-events';
26 26
import * as through from 'through2';
27 -
import {codec, Float, Int, SpannerDate, Struct} from './codec';
27 +
import {codec, Float, Int, Numeric, SpannerDate, Struct} from './codec';
28 28
import {Backup} from './backup';
29 29
import {Database} from './database';
30 30
import {
@@ -1057,6 +1057,20 @@
Loading
1057 1057
    return new codec.Int(value);
1058 1058
  }
1059 1059
1060 +
  /**
1061 +
   * Helper function to get a Cloud Spanner Numeric object.
1062 +
   *
1063 +
   * @param {string} value The numeric value as a string.
1064 +
   * @returns {Numeric}
1065 +
   *
1066 +
   * @example
1067 +
   * const {Spanner} = require('@google-cloud/spanner');
1068 +
   * const numeric = Spanner.numeric("3.141592653");
1069 +
   */
1070 +
  static numeric(value): Numeric {
1071 +
    return new codec.Numeric(value);
1072 +
  }
1073 +
1060 1074
  /**
1061 1075
   * Helper function to get a Cloud Spanner Struct object.
1062 1076
   *
@@ -1084,7 +1098,15 @@
Loading
1084 1098
 * that a callback is omitted.
1085 1099
 */
1086 1100
promisifyAll(Spanner, {
1087 -
  exclude: ['date', 'float', 'instance', 'int', 'operation', 'timestamp'],
1101 +
  exclude: [
1102 +
    'date',
1103 +
    'float',
1104 +
    'instance',
1105 +
    'int',
1106 +
    'numeric',
1107 +
    'operation',
1108 +
    'timestamp',
1109 +
  ],
1088 1110
});
1089 1111
1090 1112
/**

@@ -16,6 +16,7 @@
Loading
16 16
import {GrpcService} from './common-grpc/service';
17 17
import {PreciseDate} from '@google-cloud/precise-date';
18 18
import arrify = require('arrify');
19 +
import {Big} from 'big.js';
19 20
import * as is from 'is';
20 21
import {common as p} from 'protobufjs';
21 22
import {google as spannerClient} from '../protos/protos';
@@ -194,6 +195,23 @@
Loading
194 195
  }
195 196
}
196 197
198 +
/**
199 +
 * @typedef Numeric
200 +
 * @see Spanner.numeric
201 +
 */
202 +
export class Numeric {
203 +
  value: string;
204 +
  constructor(value: string) {
205 +
    this.value = value;
206 +
  }
207 +
  valueOf(): Big {
208 +
    return new Big(this.value);
209 +
  }
210 +
  toJSON(): string {
211 +
    return this.valueOf().toJSON();
212 +
  }
213 +
}
214 +
197 215
/**
198 216
 * @typedef JSONOptions
199 217
 * @property {boolean} [wrapNumbers=false] Indicates if the numbers should be
@@ -299,6 +317,10 @@
Loading
299 317
    case 'INT64':
300 318
      decoded = new Int(decoded);
301 319
      break;
320 +
    case spannerClient.spanner.v1.TypeCode.NUMERIC:
321 +
    case 'NUMERIC':
322 +
      decoded = new Numeric(decoded);
323 +
      break;
302 324
    case spannerClient.spanner.v1.TypeCode.TIMESTAMP:
303 325
    case 'TIMESTAMP':
304 326
      decoded = new PreciseDate(decoded);
@@ -369,6 +391,10 @@
Loading
369 391
    return value.value;
370 392
  }
371 393
394 +
  if (value instanceof Numeric) {
395 +
    return value.value;
396 +
  }
397 +
372 398
  if (Buffer.isBuffer(value)) {
373 399
    return value.toString('base64');
374 400
  }
@@ -397,6 +423,7 @@
Loading
397 423
  bool: 'BOOL',
398 424
  int64: 'INT64',
399 425
  float64: 'FLOAT64',
426 +
  numeric: 'NUMERIC',
400 427
  timestamp: 'TIMESTAMP',
401 428
  date: 'DATE',
402 429
  string: 'STRING',
@@ -430,6 +457,7 @@
Loading
430 457
 * @property {string} type The param type. Must be one of the following:
431 458
 *     - float64
432 459
 *     - int64
460 +
 *     - numeric
433 461
 *     - bool
434 462
 *     - string
435 463
 *     - bytes
@@ -466,6 +494,10 @@
Loading
466 494
    return {type: 'int64'};
467 495
  }
468 496
497 +
  if (value instanceof Numeric) {
498 +
    return {type: 'numeric'};
499 +
  }
500 +
469 501
  if (is.boolean(value)) {
470 502
    return {type: 'bool'};
471 503
  }
@@ -611,6 +643,7 @@
Loading
611 643
  SpannerDate,
612 644
  Float,
613 645
  Int,
646 +
  Numeric,
614 647
  convertFieldsToJson,
615 648
  decode,
616 649
  encode,
Files Coverage
bin 0.00%
src 99.74%
.mocharc.js 78.57%
.prettierrc.js 0.00%
Project Totals (23 files) 98.60%
actions 12
Build #248468788 -
actions 13
Build #248468788 -
actions windows
Build #248468788 -
actions 10
Build #248468788 -

No yaml found.

Create your codecov.yml to customize your Codecov experience

Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading