bigquery-client
Version:
A feature-rich Node.js client for Google BigQuery with support for CRUD operations, transactions, query building, and advanced features like aggregate functions, pagination, and logging.
46 lines (45 loc) • 1.6 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Transaction = void 0;
class Transaction {
constructor(client) {
this.queries = [];
this.client = client;
}
/**
*
* @param query query to run
* @param params query params
*/
addQuery(query, params = []) {
this.queries.push({ query, params });
}
/**
* Execute all queries in the transaction
* @returns
*
*/
excute() {
return __awaiter(this, void 0, void 0, function* () {
try {
for (const { query, params } of this.queries) {
yield this.client.query(query, params);
}
}
catch (error) {
console.error('Error executing transaction', error);
throw error;
}
});
}
}
exports.Transaction = Transaction;