Skip to content
This repository has been archived by the owner on Oct 21, 2022. It is now read-only.

Commit

Permalink
Merge pull request #23 from OpenFn/array_check
Browse files Browse the repository at this point in the history
Check if data is send to the helper
  • Loading branch information
taylordowns2000 authored Feb 8, 2021
2 parents f35339c + dda2682 commit adb28fc
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
26 changes: 25 additions & 1 deletion lib/Adaptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,13 @@ function insertMany(table, records, options) {
var client = state.client;

try {
var recordData = records(state); // Note: we select the keys of the FIRST object as the canonical template.
var recordData = records(state);

if (recordData.length === 0) {
console.log('No data found, Skipping insert.');
return state;
} // Note: we select the keys of the FIRST object as the canonical template.


var columns = Object.keys(recordData[0]);
var columnsList = columns.join(', ');
Expand Down Expand Up @@ -375,6 +381,12 @@ function upsertMany(table, uuid, records, options) {

try {
var recordData = records(state);

if (recordData.length === 0) {
console.log('No data found, Skipping upsert.');
return state;
}

var columns = Object.keys(recordData[0]);
var columnsList = columns.join(', ');
var values = recordData.map(function (x) {
Expand Down Expand Up @@ -447,6 +459,12 @@ function insertTable(tableName, columns, options) {

try {
var recordData = columns(state);

if (recordData.length === 0) {
console.log('No data found, Skipping create.');
return state;
}

var structureData = recordData.map(function (x) {
return "".concat(x.name, " ").concat(x.type, " ").concat(x.unique ? 'UNIQUE' : '', " ").concat(x.required ? 'NOT NULL' : '');
}).join(', ');
Expand Down Expand Up @@ -485,6 +503,12 @@ function modifyTable(tableName, columns, options) {

try {
var recordData = columns(state);

if (recordData.length === 0) {
console.log('No data found, Skipping modification.');
return state;
}

var structureData = recordData.map(function (x) {
return "ADD COLUMN ".concat(x.name, " ").concat(x.type, " ").concat(x.required ? 'NOT NULL' : '');
}).join(', ');
Expand Down
16 changes: 16 additions & 0 deletions src/Adaptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ export function insertMany(table, records, options) {

try {
const recordData = records(state);
if (recordData.length === 0) {
console.log('No data found, Skipping insert.');
return state;
}
// Note: we select the keys of the FIRST object as the canonical template.
const columns = Object.keys(recordData[0]);
const columnsList = columns.join(', ');
Expand Down Expand Up @@ -290,6 +294,10 @@ export function upsertMany(table, uuid, records, options) {

try {
const recordData = records(state);
if (recordData.length === 0) {
console.log('No data found, Skipping upsert.');
return state;
}
const columns = Object.keys(recordData[0]);
const columnsList = columns.join(', ');
const values = recordData.map(x => Object.values(x));
Expand Down Expand Up @@ -374,6 +382,10 @@ export function insertTable(tableName, columns, options) {
let { client } = state;
try {
const recordData = columns(state);
if (recordData.length === 0) {
console.log('No data found, Skipping create.');
return state;
}
const structureData = recordData
.map(
x =>
Expand Down Expand Up @@ -420,6 +432,10 @@ export function modifyTable(tableName, columns, options) {

try {
const recordData = columns(state);
if (recordData.length === 0) {
console.log('No data found, Skipping modification.');
return state;
}
const structureData = recordData
.map(
x => `ADD COLUMN ${x.name} ${x.type} ${x.required ? 'NOT NULL' : ''}`
Expand Down

0 comments on commit adb28fc

Please sign in to comment.