Skip to content

Commit e255095

Browse files
custom data schema support
1 parent d146df9 commit e255095

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

packages/destinations/node/bigquery/src/__tests__/index.test.ts

+9
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,13 @@ describe('Node Destination BigQuery', () => {
8686
},
8787
]);
8888
});
89+
90+
test('data', async () => {
91+
const config = await getConfig({ projectId, bigquery: { credentials } });
92+
const data = { foo: 'bar' };
93+
const mockFn = getMockFn(config);
94+
95+
await destination.push(event, config, {}, { data });
96+
expect(mockFn).toHaveBeenCalledWith('insert', [{ foo: 'bar' }]);
97+
});
8998
});

packages/destinations/node/bigquery/src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ export const destinationBigQuery: Destination = {
1919
return config;
2020
},
2121

22-
async push(event, config) {
22+
async push(event, config, mapping, options) {
2323
return await tryCatchAsync(push, (error) => {
2424
if (config.onLog) config.onLog('Push error');
2525
// @TODO queue handling
2626
throwError(error);
27-
})(event, config);
27+
})(event, config, mapping, options);
2828
},
2929
};
3030

packages/destinations/node/bigquery/src/push.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import type { WalkerOS } from '@elbwalker/types';
22
import type { PushFn, Row } from './types';
3+
import { isObject } from '@elbwalker/utils';
34

4-
export const push: PushFn = async function (event, config) {
5+
export const push: PushFn = async function (event, config, mapping, options) {
56
const { client, datasetId, tableId } = config.custom!;
67

7-
const rows = [mapEvent(event)];
8+
const row = options?.data ? options.data : mapEvent(event);
9+
const rows = [row];
810

911
await client.dataset(datasetId).table(tableId).insert(rows);
1012

@@ -40,5 +42,5 @@ export const mapEvent = (event: WalkerOS.Event): Row => {
4042
};
4143

4244
function stringify(obj?: WalkerOS.AnyObject): undefined | string {
43-
return obj && Object.keys(obj).length ? JSON.stringify(obj) : undefined;
45+
return isObject(obj) ? JSON.stringify(obj) : undefined;
4446
}

0 commit comments

Comments
 (0)