Skip to content

Commit

Permalink
rename to float()
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus committed Mar 14, 2017
1 parent a7eca2a commit 927b5c9
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
12 changes: 6 additions & 6 deletions packages/spanner/src/codec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ function SpannerDate(value) {

codec.SpannerDate = SpannerDate;

function Double(value) {
function Float(value) {
this.value = value;
}

Double.prototype.valueOf = function() {
Float.prototype.valueOf = function() {
return this.value;
};

codec.Double = Double;
codec.Float = Float;

function Int(value) {
this.value = value.toString();
Expand Down Expand Up @@ -78,7 +78,7 @@ function decode(value, field) {
break;
}
case 'FLOAT64': {
decoded = new codec.Double(decoded);
decoded = new codec.Float(decoded);
break;
}
case 'INT64': {
Expand Down Expand Up @@ -146,7 +146,7 @@ codec.decode = decode;
function encode(value) {
function preEncode(value) {
var numberShouldBeStringified =
!(value instanceof Double) &&
!(value instanceof Float) &&
is.int(value) ||
value instanceof Int ||
is.infinite(value) ||
Expand All @@ -155,7 +155,7 @@ function encode(value) {
if (is.date(value)) {
value = value.toJSON();
} else if (value instanceof SpannerDate ||
value instanceof Double ||
value instanceof Float ||
value instanceof Int) {
value = value.value;
} else if (Buffer.isBuffer(value)) {
Expand Down
11 changes: 6 additions & 5 deletions packages/spanner/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ Spanner.prototype.date = Spanner.date = function(value) {
/**
* Helper function to get a Cloud Spanner Float64 object.
*
* @param {string|number} value - The int as a number or string.
* @param {string|number} value - The float as a number or string.
* @return {object}
*
* @example
* var date = spanner.int(10);
* var date = spanner.float(10);
*/
Spanner.prototype.double = Spanner.double = function(value) {
return new codec.Double(value);
Spanner.prototype.float = Spanner.float = function(value) {
return new codec.Float(value);
};

/**
Expand Down Expand Up @@ -493,7 +493,8 @@ Spanner.prototype.operation = function(name) {
*/
common.util.promisifyAll(Spanner, {
exclude: [
'double',
'date',
'float',
'getInstanceConfigs',
'instance',
'int',
Expand Down
1 change: 1 addition & 0 deletions packages/spanner/system-test/spanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@ describe('Spanner', function() {

var EXPECTED_ROW = extend(true, {}, INSERT_ROW);
EXPECTED_ROW.DOB = DATE;
EXPECTED_ROW.Float = Spanner.float(FLOAT);
EXPECTED_ROW.Int = Spanner.int(INT);
EXPECTED_ROW.PhoneNumbers = [
Spanner.int(PHONE_NUMBERS[0]),
Expand Down
4 changes: 2 additions & 2 deletions packages/spanner/test/codec.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ describe('codec', function() {
}
});

assert(decoded instanceof codec.Double);
assert(decoded instanceof codec.Float);
assert.strictEqual(decoded.value, value);
});

Expand Down Expand Up @@ -370,7 +370,7 @@ describe('codec', function() {
});

it('should encode FLOAT64', function() {
var value = new codec.Double(10);
var value = new codec.Float(10);

var encoded = codec.encode(value);

Expand Down
3 changes: 2 additions & 1 deletion packages/spanner/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ var fakeUtil = extend({}, util, {

promisified = true;
assert.deepEqual(options.exclude, [
'double',
'date',
'float',
'getInstanceConfigs',
'instance',
'int',
Expand Down

0 comments on commit 927b5c9

Please sign in to comment.