Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import supabase from "../../supabase.app.mjs";
import fs from "fs";
import { parse } from "csv-parse/sync";

export default {
key: "supabase-batch-insert-rows",
name: "Batch Insert Rows",
description: "Inserts new rows into a database. [See the documentation](https://supabase.com/docs/reference/javascript/insert)",
version: "0.0.1",
type: "action",
props: {
supabase,
table: {
propDefinition: [
supabase,
"table",
],
description: "Name of the table to insert rows into",
},
source: {
type: "string",
label: "Source of data",
description: "Whether to enter the row data as an array of objects or to import from a CSV file",
options: [
"Array",
"CSV File",
],
reloadProps: true,
},
},
async additionalProps() {
const props = {};
if (this.source === "Array") {
props.data = {
type: "string[]",
label: "Row Data",
description: "An array of objects, each object representing a row. Enter column names and values as key/value pairs",
};
}
if (this.source === "CSV File") {
props.filePath = {
type: "string",
label: "File Path",
description: "The path to a csv file in the `/tmp` directory. [See the documentation on working with files](https://pipedream.com/docs/code/nodejs/working-with-files/#writing-a-file-to-tmp)",
};
}
return props;
},
methods: {
parseArray(arr) {
if (Array.isArray(arr)) {
return arr.map((item) => {
return typeof item === "string"
? JSON.parse(item)
: item;
});
}
if (typeof arr === "string") {
return JSON.parse(arr);
}
},
getRowsFromCSV(filePath) {
const fileContent = fs.readFileSync(filePath.includes("tmp/")
? filePath
: `/tmp/${filePath}`, "utf-8");
const rows = parse(fileContent, {
columns: true,
skip_empty_lines: true,
});
return rows;
},
},
async run({ $ }) {
const data = this.source === "CSV File"
? this.getRowsFromCSV(this.filePath)
: this.parseArray(this.data);

const response = await this.supabase.insertRow(this.table, data);

$.export("$summary", `Successfully inserted rows into table ${this.table}`);
return response;
},
};
7 changes: 4 additions & 3 deletions components/supabase/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/supabase",
"version": "0.2.2",
"version": "0.3.0",
"description": "Pipedream Supabase Components",
"main": "supabase.app.mjs",
"keywords": [
Expand All @@ -13,7 +13,8 @@
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^1.2.1",
"@supabase/supabase-js": "^2.45.6"
"@pipedream/platform": "^3.0.3",
"@supabase/supabase-js": "^2.45.6",
"csv-parse": "^5.5.6"
}
}
108 changes: 55 additions & 53 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading