@activepieces/piece-duckdb 0.0.1

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/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # pieces-duckdb
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Building
6
+
7
+ Run `nx build pieces-duckdb` to build the library.
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "@activepieces/piece-duckdb",
3
+ "version": "0.0.1",
4
+ "type": "commonjs",
5
+ "main": "./src/index.js",
6
+ "types": "./src/index.d.ts",
7
+ "dependencies": {
8
+ "@duckdb/node-api": "1.4.3-r.2",
9
+ "@sinclair/typebox": "0.34.11",
10
+ "deepmerge-ts": "7.1.0",
11
+ "nanoid": "3.3.8",
12
+ "semver": "7.6.0",
13
+ "socket.io-client": "4.8.1",
14
+ "tslib": "^2.3.0",
15
+ "@activepieces/pieces-framework": "0.23.0",
16
+ "@activepieces/shared": "0.30.4"
17
+ },
18
+ "resolutions": {
19
+ "rollup": "npm:@rollup/wasm-node"
20
+ }
21
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare const duckdb: import("@activepieces/pieces-framework").Piece<undefined>;
package/src/index.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.duckdb = void 0;
4
+ const pieces_framework_1 = require("@activepieces/pieces-framework");
5
+ const create_and_query_db_1 = require("./lib/actions/create-and-query-db");
6
+ const shared_1 = require("@activepieces/shared");
7
+ exports.duckdb = (0, pieces_framework_1.createPiece)({
8
+ displayName: 'DuckDB',
9
+ auth: pieces_framework_1.PieceAuth.None(),
10
+ minimumSupportedRelease: '0.36.1',
11
+ logoUrl: 'https://cdn.activepieces.com/pieces/duckdb.png',
12
+ description: 'Run SQL queries on an in-memory DuckDB database.',
13
+ categories: [shared_1.PieceCategory.DEVELOPER_TOOLS],
14
+ authors: ['danielpoonwj'],
15
+ actions: [create_and_query_db_1.createAndQueryDB],
16
+ triggers: [],
17
+ });
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/pieces/community/duckdb/src/index.ts"],"names":[],"mappings":";;;AAAA,qEAAwE;AAExE,2EAAqE;AACrE,iDAAqD;AAExC,QAAA,MAAM,GAAG,IAAA,8BAAW,EAAC;IAChC,WAAW,EAAE,QAAQ;IACrB,IAAI,EAAE,4BAAS,CAAC,IAAI,EAAE;IACtB,uBAAuB,EAAE,QAAQ;IACjC,OAAO,EAAE,gDAAgD;IACzD,WAAW,EAAE,kDAAkD;IAC/D,UAAU,EAAE,CAAC,sBAAa,CAAC,eAAe,CAAC;IAC3C,OAAO,EAAE,CAAC,cAAc,CAAC;IACzB,OAAO,EAAE,CAAC,sCAAgB,CAAC;IAC3B,QAAQ,EAAE,EAAE;CACb,CAAC,CAAC"}
@@ -0,0 +1,6 @@
1
+ export declare const createAndQueryDB: import("@activepieces/pieces-framework").IAction<import("@activepieces/pieces-framework").PieceAuthProperty, {
2
+ markdown: import("dist/packages/pieces/community/framework/src/lib/property/input/markdown-property").MarkDownProperty;
3
+ tables: import("@activepieces/pieces-framework").ArrayProperty<true> | import("@activepieces/pieces-framework").ArrayProperty<false>;
4
+ query: import("@activepieces/pieces-framework").ShortTextProperty<true>;
5
+ args: import("@activepieces/pieces-framework").ArrayProperty<false>;
6
+ }>;
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createAndQueryDB = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const pieces_framework_1 = require("@activepieces/pieces-framework");
6
+ const node_api_1 = require("@duckdb/node-api");
7
+ exports.createAndQueryDB = (0, pieces_framework_1.createAction)({
8
+ name: 'createAndQueryDB',
9
+ displayName: 'Create and Query DB',
10
+ description: 'Create DB from data and run query',
11
+ props: {
12
+ markdown: pieces_framework_1.Property.MarkDown({
13
+ value: `
14
+ **DO NOT** insert dynamic input directly into the query string. Instead, use $1, $2, $3 and add them in args for parameterized queries to prevent **SQL injection.**`,
15
+ }),
16
+ tables: pieces_framework_1.Property.Array({
17
+ displayName: 'Tables',
18
+ description: 'List of tables to create in the database',
19
+ required: true,
20
+ properties: {
21
+ name: pieces_framework_1.Property.ShortText({
22
+ displayName: 'Table Name',
23
+ description: 'Name of the table to create',
24
+ required: true,
25
+ }),
26
+ data: pieces_framework_1.Property.Json({
27
+ displayName: 'JSON Data',
28
+ description: 'Table data in the form of a JSON array of objects. Object keys would be taken as column names.',
29
+ required: true,
30
+ defaultValue: [],
31
+ }),
32
+ schema: pieces_framework_1.Property.Json({
33
+ displayName: 'Schema in JSON format',
34
+ description: `
35
+ Provide the schema as a JSON object. Note that only the specified columns would be loaded.
36
+ Leave empty to autodetect schema, although it is recommended to specify the schema for consistency and avoid unexpected behaviour.
37
+
38
+ More information on data types and accepted values:
39
+ - https://duckdb.org/2023/03/03/json
40
+ - https://duckdb.org/docs/stable/sql/data_types/overview
41
+ `.trim(),
42
+ required: false,
43
+ defaultValue: {},
44
+ }),
45
+ },
46
+ }),
47
+ query: pieces_framework_1.Property.ShortText({
48
+ displayName: 'Query',
49
+ description: 'Please use $1, $2, etc. for parameterized queries to avoid SQL injection.',
50
+ required: true,
51
+ }),
52
+ args: pieces_framework_1.Property.Array({
53
+ displayName: 'Arguments',
54
+ description: 'Arguments to be used in the query',
55
+ required: false,
56
+ }),
57
+ },
58
+ run(context) {
59
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
60
+ var _a, _b;
61
+ const instance = yield node_api_1.DuckDBInstance.create(':memory:');
62
+ const connection = yield instance.connect();
63
+ yield connection.run(`
64
+ SET enable_logging = 0;
65
+ SET enable_external_access = false;
66
+ SET lock_configuration = true;
67
+ `);
68
+ const dbTables = (_a = context.propsValue.tables) !== null && _a !== void 0 ? _a : [];
69
+ for (const dbTable of dbTables) {
70
+ const dbData = JSON.stringify(dbTable.data);
71
+ let dbSchema = null;
72
+ if (dbTable.schema) {
73
+ dbSchema = JSON.stringify([dbTable.schema]);
74
+ }
75
+ else {
76
+ const schemaResult = yield connection.run('SELECT json_structure($sourceData) AS schema', { sourceData: dbData });
77
+ const detectedSchema = yield schemaResult.getRows();
78
+ dbSchema = detectedSchema[0][0];
79
+ }
80
+ yield connection.run(`
81
+ CREATE TABLE ${dbTable.name} AS
82
+ SELECT UNNEST(JSON_TRANSFORM($sourceData, $sourceSchema), recursive := true);
83
+ `, {
84
+ sourceData: dbData,
85
+ sourceSchema: dbSchema,
86
+ });
87
+ }
88
+ const queryArgs = (_b = context.propsValue.args) !== null && _b !== void 0 ? _b : [];
89
+ const formattedArgs = {};
90
+ for (let i = 0; i < queryArgs.length; i++) {
91
+ const idx = (i + 1).toString();
92
+ formattedArgs[idx] = queryArgs[i];
93
+ }
94
+ const reader = yield connection.runAndReadAll(context.propsValue.query, formattedArgs);
95
+ const results = reader.getRowObjectsJson();
96
+ connection.closeSync();
97
+ return results;
98
+ });
99
+ },
100
+ });
101
+ //# sourceMappingURL=create-and-query-db.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-and-query-db.js","sourceRoot":"","sources":["../../../../../../../../packages/pieces/community/duckdb/src/lib/actions/create-and-query-db.ts"],"names":[],"mappings":";;;;AAAA,qEAAwE;AAExE,+CAAkD;AAErC,QAAA,gBAAgB,GAAG,IAAA,+BAAY,EAAC;IAC3C,IAAI,EAAE,kBAAkB;IACxB,WAAW,EAAE,qBAAqB;IAClC,WAAW,EAAE,mCAAmC;IAChD,KAAK,EAAE;QACL,QAAQ,EAAE,2BAAQ,CAAC,QAAQ,CAAC;YAC1B,KAAK,EAAE;2KAC8J;SACtK,CAAC;QACF,MAAM,EAAE,2BAAQ,CAAC,KAAK,CAAC;YACrB,WAAW,EAAE,QAAQ;YACrB,WAAW,EAAE,0CAA0C;YACvD,QAAQ,EAAE,IAAI;YACd,UAAU,EAAE;gBACV,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