@8ms/helpers 1.3.1 → 1.3.3
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/createDataset.d.ts +11 -0
- package/google/bigQuery/createDataset.js +22 -0
- package/google/bigQuery/createTable.d.ts +1 -2
- package/google/bigQuery/createTable.js +1 -2
- package/google/bigQuery/getClient.js +1 -1
- package/google/bigQuery/isDatasetExists.d.ts +11 -0
- package/google/bigQuery/isDatasetExists.js +25 -0
- package/package.json +1 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type CreateDataset = {
|
|
2
|
+
datasetId: string;
|
|
3
|
+
projectId?: string;
|
|
4
|
+
options: object;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Create a Dataset if it doesn't already exist.
|
|
8
|
+
* Returns table instance.
|
|
9
|
+
*/
|
|
10
|
+
declare const createDataset: ({ datasetId, options, projectId }: CreateDataset) => Promise<void>;
|
|
11
|
+
export default createDataset;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const getClient_1 = __importDefault(require("./getClient"));
|
|
7
|
+
const isDatasetExists_1 = __importDefault(require("./isDatasetExists"));
|
|
8
|
+
/**
|
|
9
|
+
* Create a Dataset if it doesn't already exist.
|
|
10
|
+
* Returns table instance.
|
|
11
|
+
*/
|
|
12
|
+
const createDataset = async ({ datasetId, options, projectId }) => {
|
|
13
|
+
const datasetExists = await (0, isDatasetExists_1.default)({
|
|
14
|
+
datasetId,
|
|
15
|
+
projectId,
|
|
16
|
+
});
|
|
17
|
+
if (!datasetExists) {
|
|
18
|
+
let client = (0, getClient_1.default)({ projectId });
|
|
19
|
+
await client.createDataset(datasetId, options || {});
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
exports.default = createDataset;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
type CreateTable = {
|
|
2
2
|
datasetId: string;
|
|
3
3
|
projectId?: string;
|
|
4
|
-
options
|
|
4
|
+
options?: object;
|
|
5
5
|
tableId: string;
|
|
6
6
|
};
|
|
7
7
|
/**
|
|
8
8
|
* Create a Table if it doesn't already exist.
|
|
9
|
-
* Returns table instance.
|
|
10
9
|
*/
|
|
11
10
|
declare const createTable: ({ datasetId, options, projectId, tableId }: CreateTable) => Promise<void>;
|
|
12
11
|
export default createTable;
|
|
@@ -7,7 +7,6 @@ const IsTableExists_1 = __importDefault(require("./IsTableExists"));
|
|
|
7
7
|
const getClient_1 = __importDefault(require("./getClient"));
|
|
8
8
|
/**
|
|
9
9
|
* Create a Table if it doesn't already exist.
|
|
10
|
-
* Returns table instance.
|
|
11
10
|
*/
|
|
12
11
|
const createTable = async ({ datasetId, options, projectId, tableId }) => {
|
|
13
12
|
const tableExists = await (0, IsTableExists_1.default)({
|
|
@@ -19,7 +18,7 @@ const createTable = async ({ datasetId, options, projectId, tableId }) => {
|
|
|
19
18
|
let client = (0, getClient_1.default)({ projectId });
|
|
20
19
|
await client
|
|
21
20
|
.dataset(datasetId)
|
|
22
|
-
.createTable(tableId, options);
|
|
21
|
+
.createTable(tableId, options || {});
|
|
23
22
|
}
|
|
24
23
|
};
|
|
25
24
|
exports.default = createTable;
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
5
5
|
*/
|
|
6
6
|
const getClient = ({ projectId }) => {
|
|
7
7
|
let client = global.googleBigQueryClient;
|
|
8
|
-
if (projectId !== global.googleBigQueryDefaultProjectId) {
|
|
8
|
+
if (undefined !== projectId && projectId !== global.googleBigQueryDefaultProjectId) {
|
|
9
9
|
const { BigQuery } = require('@google-cloud/bigquery');
|
|
10
10
|
client = new BigQuery({
|
|
11
11
|
credentials: global.googleBigQueryDefault.credentials,
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type IsDatasetExists = {
|
|
2
|
+
datasetId: string;
|
|
3
|
+
projectId?: string;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Check to see whether a given BigQuery dataset exists.
|
|
7
|
+
* Based off:
|
|
8
|
+
* https://github.com/googleapis/nodejs-bigquery/blob/main/samples/getDataset.js
|
|
9
|
+
*/
|
|
10
|
+
declare const isDatasetExists: ({ datasetId, projectId }: IsDatasetExists) => Promise<boolean>;
|
|
11
|
+
export default isDatasetExists;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const getClient_1 = __importDefault(require("./getClient"));
|
|
7
|
+
/**
|
|
8
|
+
* Check to see whether a given BigQuery dataset exists.
|
|
9
|
+
* Based off:
|
|
10
|
+
* https://github.com/googleapis/nodejs-bigquery/blob/main/samples/getDataset.js
|
|
11
|
+
*/
|
|
12
|
+
const isDatasetExists = async ({ datasetId, projectId }) => {
|
|
13
|
+
let response;
|
|
14
|
+
let client = (0, getClient_1.default)({ projectId });
|
|
15
|
+
try {
|
|
16
|
+
await client.dataset(datasetId)
|
|
17
|
+
.get();
|
|
18
|
+
response = true;
|
|
19
|
+
}
|
|
20
|
+
catch (exception) {
|
|
21
|
+
response = false;
|
|
22
|
+
}
|
|
23
|
+
return response;
|
|
24
|
+
};
|
|
25
|
+
exports.default = isDatasetExists;
|