Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bigquery: support SQL parameters #1854

Merged
merged 12 commits into from
Dec 6, 2016
Prev Previous commit
Next Next commit
tests
  • Loading branch information
stephenplusplus committed Dec 6, 2016
commit 29b4ea6ca699e091551bb92e09980c1998d69ebe
2 changes: 1 addition & 1 deletion packages/bigquery/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ BigQuery.prototype.datetime = function(value) {
var time;

if (value.hours) {
time = new BigQuery.time(value);
time = BigQuery.time(value);
}

value = format('{y}-{m}-{d}{time}', {
Expand Down
64 changes: 64 additions & 0 deletions packages/bigquery/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,17 @@ describe('BigQuery', function() {
});

describe('datetime', function() {
var INPUT_STRING = '2017-1-1 14:2:38.883388';
var INPUT_OBJ = {
year: 2017,
month: 1,
day: 1,
hours: 14,
minutes: 2,
seconds: 38,
fractional: 883388
};

it('should expose static and instance constructors', function() {
var staticDt = BigQuery.datetime();
assert(staticDt instanceof BigQuery.datetime);
Expand All @@ -156,9 +167,37 @@ describe('BigQuery', function() {
assert(instanceDt instanceof BigQuery.datetime);
assert(instanceDt instanceof bq.datetime);
});

it('should accept a string', function() {
var datetime = bq.datetime(INPUT_STRING);
assert.strictEqual(datetime.value, INPUT_STRING);
});

it('should accept an object', function() {
var datetime = bq.datetime(INPUT_OBJ);
assert.strictEqual(datetime.value, INPUT_STRING);
});

it('should not include time if hours not provided', function() {
var datetime = bq.datetime({
year: 2016,
month: 1,
day: 1
});

assert.strictEqual(datetime.value, '2016-1-1');
});
});

describe('time', function() {
var INPUT_STRING = '14:2:38.883388';
var INPUT_OBJ = {
hours: 14,
minutes: 2,
seconds: 38,
fractional: 883388
};

it('should expose static and instance constructors', function() {
var staticT = BigQuery.time();
assert(staticT instanceof BigQuery.time);
Expand All @@ -168,6 +207,31 @@ describe('BigQuery', function() {
assert(instanceT instanceof BigQuery.time);
assert(instanceT instanceof bq.time);
});

it('should accept a string', function() {
var time = bq.time(INPUT_STRING);
assert.strictEqual(time.value, INPUT_STRING);
});

it('should accept an object', function() {
var time = bq.time(INPUT_OBJ);
assert.strictEqual(time.value, INPUT_STRING);
});

it('should default minutes and seconds to 0', function() {
var time = bq.time({
hours: 14
});
assert.strictEqual(time.value, '14:0:0');
});

it('should not include fractional digits if not provided', function() {
var input = extend({}, INPUT_OBJ);
delete input.fractional;

var time = bq.time(input);
assert.strictEqual(time.value, '14:2:38');
});
});

describe('getType_', function() {
Expand Down