@8ms/helpers 1.2.17 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/google/bigQuery/IsTableExists.d.ts +2 -1
- package/google/bigQuery/IsTableExists.js +7 -2
- package/google/bigQuery/createTable.d.ts +2 -1
- package/google/bigQuery/createTable.js +6 -2
- package/google/bigQuery/getClient.d.ts +8 -0
- package/google/bigQuery/getClient.js +17 -0
- package/google/bigQuery/initClient.js +5 -2
- package/google/bigQuery/loadData.d.ts +1 -0
- package/google/bigQuery/loadData.js +7 -1
- package/google/bigQuery/query.d.ts +2 -1
- package/google/bigQuery/query.js +7 -2
- package/package.json +1 -1
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
type IsTableExists = {
|
|
2
2
|
datasetId: string;
|
|
3
|
+
projectId?: string;
|
|
3
4
|
tableId: string;
|
|
4
5
|
};
|
|
5
6
|
/**
|
|
6
7
|
* Check to see whether a given BigQuery table exists.
|
|
7
8
|
* https://cloud.google.com/bigquery/docs/samples/bigquery-table-exists
|
|
8
9
|
*/
|
|
9
|
-
declare const isTableExists: ({ datasetId, tableId }: IsTableExists) => Promise<boolean>;
|
|
10
|
+
declare const isTableExists: ({ datasetId, projectId, tableId }: IsTableExists) => Promise<boolean>;
|
|
10
11
|
export default isTableExists;
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const getClient_1 = __importDefault(require("./getClient"));
|
|
3
7
|
/**
|
|
4
8
|
* Check to see whether a given BigQuery table exists.
|
|
5
9
|
* https://cloud.google.com/bigquery/docs/samples/bigquery-table-exists
|
|
6
10
|
*/
|
|
7
|
-
const isTableExists = async ({ datasetId, tableId }) => {
|
|
11
|
+
const isTableExists = async ({ datasetId, projectId, tableId }) => {
|
|
8
12
|
let response;
|
|
9
|
-
|
|
13
|
+
let client = (0, getClient_1.default)({ projectId });
|
|
14
|
+
const dataset = client.dataset(datasetId);
|
|
10
15
|
try {
|
|
11
16
|
await dataset.table(tableId)
|
|
12
17
|
.get();
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
type CreateTable = {
|
|
2
2
|
datasetId: string;
|
|
3
|
+
projectId?: string;
|
|
3
4
|
options: object;
|
|
4
5
|
tableId: string;
|
|
5
6
|
};
|
|
@@ -7,5 +8,5 @@ type CreateTable = {
|
|
|
7
8
|
* Create a Table if it doesn't already exist.
|
|
8
9
|
* Returns table instance.
|
|
9
10
|
*/
|
|
10
|
-
declare const createTable: ({ datasetId, options, tableId }: CreateTable) => Promise<void>;
|
|
11
|
+
declare const createTable: ({ datasetId, options, projectId, tableId }: CreateTable) => Promise<void>;
|
|
11
12
|
export default createTable;
|
|
@@ -4,17 +4,21 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const IsTableExists_1 = __importDefault(require("./IsTableExists"));
|
|
7
|
+
const getClient_1 = __importDefault(require("./getClient"));
|
|
7
8
|
/**
|
|
8
9
|
* Create a Table if it doesn't already exist.
|
|
9
10
|
* Returns table instance.
|
|
10
11
|
*/
|
|
11
|
-
const createTable = async ({ datasetId, options, tableId }) => {
|
|
12
|
+
const createTable = async ({ datasetId, options, projectId, tableId }) => {
|
|
12
13
|
const tableExists = await (0, IsTableExists_1.default)({
|
|
13
14
|
datasetId,
|
|
15
|
+
projectId,
|
|
14
16
|
tableId
|
|
15
17
|
});
|
|
16
18
|
if (!tableExists) {
|
|
17
|
-
|
|
19
|
+
let client = (0, getClient_1.default)({ projectId });
|
|
20
|
+
await client
|
|
21
|
+
.dataset(datasetId)
|
|
18
22
|
.createTable(tableId, options);
|
|
19
23
|
}
|
|
20
24
|
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* Create a new client if the project id differs from the global.
|
|
5
|
+
*/
|
|
6
|
+
const getClient = ({ projectId }) => {
|
|
7
|
+
let client = global.googleBigQueryClient;
|
|
8
|
+
if (projectId !== global.googleBigQueryDefaultProjectId) {
|
|
9
|
+
const { BigQuery } = require('@google-cloud/bigquery');
|
|
10
|
+
client = new BigQuery({
|
|
11
|
+
credentials: global.googleBigQueryDefault.credentials,
|
|
12
|
+
projectId: projectId,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
return client;
|
|
16
|
+
};
|
|
17
|
+
exports.default = getClient;
|
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const getConfig_1 = __importDefault(require("../getConfig"));
|
|
7
|
+
global.googleBigQueryDefaultProjectId = null;
|
|
7
8
|
global.googleBigQueryClient = null;
|
|
8
9
|
/**
|
|
9
10
|
* Initialise the Big Query client.
|
|
@@ -13,9 +14,11 @@ const initClient = ({ parameter, projectId }) => {
|
|
|
13
14
|
if (!global.googleBigQueryClient) {
|
|
14
15
|
const { BigQuery } = require('@google-cloud/bigquery');
|
|
15
16
|
const formattedConfig = (0, getConfig_1.default)({ parameter });
|
|
17
|
+
global.googleBigQueryDefault.credentials = formattedConfig;
|
|
18
|
+
global.googleBigQueryDefault.projectId = projectId;
|
|
16
19
|
global.googleBigQueryClient = new BigQuery({
|
|
17
|
-
credentials:
|
|
18
|
-
projectId: projectId,
|
|
20
|
+
credentials: global.googleBigQueryDefault.credentials,
|
|
21
|
+
projectId: global.googleBigQueryDefault.projectId,
|
|
19
22
|
});
|
|
20
23
|
}
|
|
21
24
|
};
|
|
@@ -4,16 +4,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const IsTableExists_1 = __importDefault(require("./IsTableExists"));
|
|
7
|
+
const getClient_1 = __importDefault(require("./getClient"));
|
|
7
8
|
/**
|
|
8
9
|
* Load data into a given table.
|
|
9
10
|
*/
|
|
10
11
|
const loadData = async ({ file, table }) => {
|
|
11
12
|
const tableExists = await (0, IsTableExists_1.default)({
|
|
12
13
|
datasetId: table.datasetId,
|
|
14
|
+
projectId: table.projectId,
|
|
13
15
|
tableId: table.tableId,
|
|
14
16
|
});
|
|
15
17
|
if (tableExists) {
|
|
16
|
-
|
|
18
|
+
let client = (0, getClient_1.default)({
|
|
19
|
+
projectId: table.projectId
|
|
20
|
+
});
|
|
21
|
+
await client
|
|
22
|
+
.dataset(table.datasetId)
|
|
17
23
|
.table(table.tableId)
|
|
18
24
|
.load(global.googleStorageClient.bucket(file.bucket)
|
|
19
25
|
.file(file.key), file.metadata);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
type Query = {
|
|
2
2
|
input: string;
|
|
3
|
+
projectId?: string;
|
|
3
4
|
};
|
|
4
5
|
/**
|
|
5
6
|
* Build the query and return the data.
|
|
6
7
|
*/
|
|
7
|
-
declare const query: ({ input }: Query) => Promise<any>;
|
|
8
|
+
declare const query: ({ input, projectId }: Query) => Promise<any>;
|
|
8
9
|
export default query;
|
package/google/bigQuery/query.js
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const getClient_1 = __importDefault(require("./getClient"));
|
|
3
7
|
/**
|
|
4
8
|
* Build the query and return the data.
|
|
5
9
|
*/
|
|
6
|
-
const query = async ({ input }) => {
|
|
7
|
-
|
|
10
|
+
const query = async ({ input, projectId }) => {
|
|
11
|
+
let client = (0, getClient_1.default)({ projectId });
|
|
12
|
+
const apiResponse = await client.query(input);
|
|
8
13
|
return apiResponse;
|
|
9
14
|
};
|
|
10
15
|
exports.default = query;
|