@divyacon/piece-mysql 0.0.0-stage → 0.1.0

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.
Files changed (48) hide show
  1. package/LICENSE.MIT-AP +24 -0
  2. package/dist/index.d.ts +15 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +52 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/lib/actions/delete-row.d.ts +27 -0
  7. package/dist/lib/actions/delete-row.d.ts.map +1 -0
  8. package/dist/lib/actions/delete-row.js +46 -0
  9. package/dist/lib/actions/delete-row.js.map +1 -0
  10. package/dist/lib/actions/execute-query.d.ts +14 -0
  11. package/dist/lib/actions/execute-query.d.ts.map +1 -0
  12. package/dist/lib/actions/execute-query.js +43 -0
  13. package/dist/lib/actions/execute-query.js.map +1 -0
  14. package/dist/lib/actions/find-rows.d.ts +28 -0
  15. package/dist/lib/actions/find-rows.d.ts.map +1 -0
  16. package/dist/lib/actions/find-rows.js +54 -0
  17. package/dist/lib/actions/find-rows.js.map +1 -0
  18. package/dist/lib/actions/get-tables.d.ts +9 -0
  19. package/dist/lib/actions/get-tables.d.ts.map +1 -0
  20. package/dist/lib/actions/get-tables.js +30 -0
  21. package/dist/lib/actions/get-tables.js.map +1 -0
  22. package/dist/lib/actions/index.d.ts +115 -0
  23. package/dist/lib/actions/index.d.ts.map +1 -0
  24. package/dist/lib/actions/index.js +20 -0
  25. package/dist/lib/actions/index.js.map +1 -0
  26. package/dist/lib/actions/insert-row.d.ts +25 -0
  27. package/dist/lib/actions/insert-row.d.ts.map +1 -0
  28. package/dist/lib/actions/insert-row.js +42 -0
  29. package/dist/lib/actions/insert-row.js.map +1 -0
  30. package/dist/lib/actions/update-row.d.ts +27 -0
  31. package/dist/lib/actions/update-row.d.ts.map +1 -0
  32. package/dist/lib/actions/update-row.js +52 -0
  33. package/dist/lib/actions/update-row.js.map +1 -0
  34. package/dist/lib/common/index.d.ts +24 -0
  35. package/dist/lib/common/index.d.ts.map +1 -0
  36. package/dist/lib/common/index.js +79 -0
  37. package/dist/lib/common/index.js.map +1 -0
  38. package/package.json +46 -3
  39. package/src/index.ts +52 -0
  40. package/src/lib/actions/delete-row.ts +41 -0
  41. package/src/lib/actions/execute-query.ts +38 -0
  42. package/src/lib/actions/find-rows.ts +49 -0
  43. package/src/lib/actions/get-tables.ts +22 -0
  44. package/src/lib/actions/index.ts +15 -0
  45. package/src/lib/actions/insert-row.ts +35 -0
  46. package/src/lib/actions/update-row.ts +44 -0
  47. package/src/lib/common/index.ts +83 -0
  48. package/README.md +0 -3
@@ -0,0 +1 @@
1
+ {"version":3,"file":"insert-row.js","sourceRoot":"","sources":["../../../src/lib/actions/insert-row.ts"],"names":[],"mappings":";;;AAAA,kGAAkG;AAClG,qEAAqE;AACrE,gEAAmE;AACnE,sCAA2F;AAC3F,6BAAkC;AAGlC,kBAAe,IAAA,+BAAY,EAAC;IAC1B,IAAI,EAAE,aAAS;IACf,IAAI,EAAE,YAAY;IAClB,WAAW,EAAE,YAAY;IACzB,WAAW,EAAE,gCAAgC;IAC7C,QAAQ,EAAE,MAAM;IAChB,UAAU,EAAE,EAAE,WAAW,EAAE,+NAA+N,EAAE,UAAU,EAAE,KAAK,EAAE;IAC/Q,KAAK,EAAE;QACL,QAAQ,EAAE,oBAAW,CAAC,QAAQ;QAC9B,KAAK,EAAE,oBAAW,CAAC,KAAK,EAAE;QAC1B,MAAM,EAAE,2BAAQ,CAAC,MAAM,CAAC;YACtB,WAAW,EAAE,QAAQ;YACrB,QAAQ,EAAE,IAAI;SACf,CAAC;KACH;IACK,GAAG,CAAC,OAAO;;YACf,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;YACtD,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAA,2BAAkB,EAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACpE,MAAM,QAAQ,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACjD,MAAM,EAAE,GAAG,eAAe,IAAA,2BAAkB,EAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,QAAQ,aAAa,QAAQ,IAAI,CAAC;YAC7G,MAAM,IAAI,GAAG,MAAM,IAAA,qBAAY,EAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;YAClE,IAAI,CAAC;gBACH,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC/D,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;gBAC5C,OAAO,MAAM,CAAC;YAChB,CAAC;oBAAS,CAAC;gBACT,MAAM,IAAI,CAAC,GAAG,EAAE,CAAC;YACnB,CAAC;QACH,CAAC;KAAA;CACF,CAAC,CAAC"}
@@ -0,0 +1,27 @@
1
+ declare const _default: import("@agnocon/pieces-framework").IAction<import("@agnocon/pieces-framework").CustomAuthProperty<{
2
+ host: import("@agnocon/pieces-framework").ShortTextProperty<true>;
3
+ port: import("@agnocon/pieces-framework").NumberProperty<true>;
4
+ user: import("@agnocon/pieces-framework").ShortTextProperty<true>;
5
+ password: import("@agnocon/pieces-framework").SecretTextProperty<true>;
6
+ database: import("@agnocon/pieces-framework").ShortTextProperty<false>;
7
+ }>, {
8
+ timezone: import("@agnocon/pieces-framework").ShortTextProperty<false>;
9
+ table: import("@agnocon/pieces-framework").DropdownProperty<string, false, import("@agnocon/pieces-framework").CustomAuthProperty<{
10
+ host: import("@agnocon/pieces-framework").ShortTextProperty<true>;
11
+ port: import("@agnocon/pieces-framework").NumberProperty<true>;
12
+ user: import("@agnocon/pieces-framework").ShortTextProperty<true>;
13
+ password: import("@agnocon/pieces-framework").SecretTextProperty<true>;
14
+ database: import("@agnocon/pieces-framework").ShortTextProperty<false>;
15
+ }>> | import("@agnocon/pieces-framework").DropdownProperty<string, true, import("@agnocon/pieces-framework").CustomAuthProperty<{
16
+ host: import("@agnocon/pieces-framework").ShortTextProperty<true>;
17
+ port: import("@agnocon/pieces-framework").NumberProperty<true>;
18
+ user: import("@agnocon/pieces-framework").ShortTextProperty<true>;
19
+ password: import("@agnocon/pieces-framework").SecretTextProperty<true>;
20
+ database: import("@agnocon/pieces-framework").ShortTextProperty<false>;
21
+ }>>;
22
+ values: import("@agnocon/pieces-framework").ObjectProperty<true>;
23
+ search_column: import("@agnocon/pieces-framework").ShortTextProperty<true>;
24
+ search_value: import("@agnocon/pieces-framework").ShortTextProperty<true>;
25
+ }>;
26
+ export default _default;
27
+ //# sourceMappingURL=update-row.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update-row.d.ts","sourceRoot":"","sources":["../../../src/lib/actions/update-row.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAMA,wBAuCG"}
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ // Vendored from Activepieces packages/pieces/community/mysql/src/lib/actions/update-row.ts (MIT).
5
+ // Generated by packages/scripts/vendor-ap.mjs - do not edit by hand.
6
+ const pieces_framework_1 = require("@agnocon/pieces-framework");
7
+ const common_1 = require("../common");
8
+ const __1 = require("../..");
9
+ exports.default = (0, pieces_framework_1.createAction)({
10
+ auth: __1.mysqlAuth,
11
+ name: 'update_row',
12
+ displayName: 'Update Row',
13
+ description: 'Updates one or more rows in a table',
14
+ audience: 'both',
15
+ aiMetadata: { description: 'Updates every row in a MySQL table whose search column equals a given value, setting the supplied column-to-value pairs. Use to modify existing records matched by a single column. Idempotent: re-running with the same input writes the same values and has no additional effect.', idempotent: true },
16
+ props: {
17
+ timezone: common_1.mysqlCommon.timezone,
18
+ table: common_1.mysqlCommon.table(),
19
+ values: pieces_framework_1.Property.Object({
20
+ displayName: 'Values',
21
+ required: true,
22
+ }),
23
+ search_column: pieces_framework_1.Property.ShortText({
24
+ displayName: 'Search Column',
25
+ required: true,
26
+ }),
27
+ search_value: pieces_framework_1.Property.ShortText({
28
+ displayName: 'Search Value',
29
+ required: true,
30
+ }),
31
+ },
32
+ run(context) {
33
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
34
+ const fields = Object.keys(context.propsValue.values);
35
+ const qsValues = fields.map((f) => (0, common_1.sanitizeColumnName)(f) + '=?').join(',');
36
+ const qs = `UPDATE ${(0, common_1.sanitizeColumnName)(context.propsValue.table)} SET ${qsValues} WHERE ${(0, common_1.sanitizeColumnName)(context.propsValue.search_column)}=?;`;
37
+ const conn = yield (0, common_1.mysqlConnect)(context.auth, context.propsValue);
38
+ try {
39
+ const values = fields.map((f) => context.propsValue.values[f]);
40
+ const result = yield conn.query(qs, [
41
+ ...values,
42
+ context.propsValue.search_value,
43
+ ]);
44
+ return result;
45
+ }
46
+ finally {
47
+ yield conn.end();
48
+ }
49
+ });
50
+ },
51
+ });
52
+ //# sourceMappingURL=update-row.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update-row.js","sourceRoot":"","sources":["../../../src/lib/actions/update-row.ts"],"names":[],"mappings":";;;AAAA,kGAAkG;AAClG,qEAAqE;AACrE,gEAAmE;AACnE,sCAA0E;AAC1E,6BAAkC;AAElC,kBAAe,IAAA,+BAAY,EAAC;IAC1B,IAAI,EAAE,aAAS;IACf,IAAI,EAAE,YAAY;IAClB,WAAW,EAAE,YAAY;IACzB,WAAW,EAAE,qCAAqC;IAClD,QAAQ,EAAE,MAAM;IAChB,UAAU,EAAE,EAAE,WAAW,EAAE,qRAAqR,EAAE,UAAU,EAAE,IAAI,EAAE;IACpU,KAAK,EAAE;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U,CAAC,YAAY;iBAChC,CAAC,CAAC;gBACH,OAAO,MAAM,CAAC;YAChB,CAAC;oBAAS,CAAC;gBACT,MAAM,IAAI,CAAC,GAAG,EAAE,CAAC;YACnB,CAAC;QACH,CAAC;KAAA;CACF,CAAC,CAAC"}
@@ -0,0 +1,24 @@
1
+ import { AppConnectionValueForAuthProperty, StaticPropsValue } from '@agnocon/pieces-framework';
2
+ import { Connection } from 'promise-mysql';
3
+ import { mysqlAuth } from '../..';
4
+ export declare const warningMarkdown: import("@agnocon/pieces-framework/dist/lib/property/input/markdown-property").MarkDownProperty;
5
+ export declare function mysqlConnect(auth: AppConnectionValueForAuthProperty<typeof mysqlAuth>, propsValue: StaticPropsValue<any>): Promise<Connection>;
6
+ export declare function mysqlGetTableNames(conn: Connection): Promise<string[]>;
7
+ export declare const mysqlCommon: {
8
+ timezone: import("@agnocon/pieces-framework").ShortTextProperty<false>;
9
+ table: (required?: boolean) => import("@agnocon/pieces-framework").DropdownProperty<string, false, import("@agnocon/pieces-framework").CustomAuthProperty<{
10
+ host: import("@agnocon/pieces-framework").ShortTextProperty<true>;
11
+ port: import("@agnocon/pieces-framework").NumberProperty<true>;
12
+ user: import("@agnocon/pieces-framework").ShortTextProperty<true>;
13
+ password: import("@agnocon/pieces-framework").SecretTextProperty<true>;
14
+ database: import("@agnocon/pieces-framework").ShortTextProperty<false>;
15
+ }>> | import("@agnocon/pieces-framework").DropdownProperty<string, true, import("@agnocon/pieces-framework").CustomAuthProperty<{
16
+ host: import("@agnocon/pieces-framework").ShortTextProperty<true>;
17
+ port: import("@agnocon/pieces-framework").NumberProperty<true>;
18
+ user: import("@agnocon/pieces-framework").ShortTextProperty<true>;
19
+ password: import("@agnocon/pieces-framework").SecretTextProperty<true>;
20
+ database: import("@agnocon/pieces-framework").ShortTextProperty<false>;
21
+ }>>;
22
+ };
23
+ export declare function sanitizeColumnName(name: string | undefined): string;
24
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/common/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,iCAAiC,EAGjC,gBAAgB,EACjB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,UAAU,EAAoB,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGlC,eAAO,MAAM,eAAe,gGAK1B,CAAC;AAEH,wBAAsB,YAAY,CAChC,IAAI,EAAE,iCAAiC,CAAC,OAAO,SAAS,CAAC,EACzD,UAAU,EAAE,gBAAgB,CAAC,GAAG,CAAC,GAChC,OAAO,CAAC,UAAU,CAAC,CAUrB;AAED,wBAAsB,kBAAkB,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAG5E;AAED,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;CAqCvB,CAAC;AAGF,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAKnE"}
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.mysqlCommon = exports.warningMarkdown = void 0;
4
+ exports.mysqlConnect = mysqlConnect;
5
+ exports.mysqlGetTableNames = mysqlGetTableNames;
6
+ exports.sanitizeColumnName = sanitizeColumnName;
7
+ const tslib_1 = require("tslib");
8
+ // Vendored from Activepieces packages/pieces/community/mysql/src/lib/common/index.ts (MIT).
9
+ // Generated by packages/scripts/vendor-ap.mjs - do not edit by hand.
10
+ const pieces_framework_1 = require("@agnocon/pieces-framework");
11
+ const promise_mysql_1 = require("promise-mysql");
12
+ const __1 = require("../..");
13
+ const sqlstring_1 = tslib_1.__importDefault(require("sqlstring"));
14
+ exports.warningMarkdown = pieces_framework_1.Property.MarkDown({
15
+ value: `
16
+ **DO NOT** use dynamic input directly in the query string or column names.
17
+ \n
18
+ Use **?** in the query and dynamic values in args/values for parameterized queries to prevent **SQL injection**.`
19
+ });
20
+ function mysqlConnect(auth, propsValue) {
21
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
22
+ const conn = yield (0, promise_mysql_1.createConnection)({
23
+ host: auth.props.host,
24
+ port: auth.props.port || 3306,
25
+ user: auth.props.user,
26
+ password: auth.props.password,
27
+ database: auth.props.database || undefined,
28
+ timezone: propsValue.timezone,
29
+ });
30
+ return conn;
31
+ });
32
+ }
33
+ function mysqlGetTableNames(conn) {
34
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
35
+ const result = yield conn.query('SHOW TABLES;');
36
+ return result.map((row) => row[Object.keys(row)[0]]);
37
+ });
38
+ }
39
+ exports.mysqlCommon = {
40
+ timezone: pieces_framework_1.Property.ShortText({
41
+ displayName: 'Timezone',
42
+ description: 'Timezone for the MySQL server to use',
43
+ required: false,
44
+ }),
45
+ table: (required = true) => pieces_framework_1.Property.Dropdown({
46
+ auth: __1.mysqlAuth,
47
+ displayName: 'Table',
48
+ required,
49
+ refreshers: [],
50
+ options: (_a) => tslib_1.__awaiter(void 0, [_a], void 0, function* ({ auth }) {
51
+ if (!auth) {
52
+ return {
53
+ disabled: true,
54
+ placeholder: 'Connect to your database first',
55
+ options: [],
56
+ };
57
+ }
58
+ const conn = yield mysqlConnect(auth, { auth });
59
+ const tables = yield mysqlGetTableNames(conn);
60
+ yield conn.end();
61
+ return {
62
+ disabled: false,
63
+ options: tables.map((table) => {
64
+ return {
65
+ label: table,
66
+ value: table,
67
+ };
68
+ }),
69
+ };
70
+ }),
71
+ }),
72
+ };
73
+ function sanitizeColumnName(name) {
74
+ if (name == '*') {
75
+ return name;
76
+ }
77
+ return sqlstring_1.default.escapeId(name);
78
+ }
79
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/common/index.ts"],"names":[],"mappings":";;;AAmBA,oCAaC;AAED,gDAGC;AA0CD,gDAKC;;AApFD,4FAA4F;AAC5F,qE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AE,EAAE;QACd,OAAO,EAAE,KAAiB,EAAE,oDAAZ,EAAE,IAAI,EAAE;YACtB,IAAI,CAAC,IAAI,EAAE,CAAC;gBACV,OAAO;oBACL,QAAQ,EAAE,IAAI;oBACd,WAAW,EAAE,gCAAgC;oBAC7C,OAAO,EAAE,EAAE;iBACZ,CAAC;YACJ,CAAC;YACD,MAAM,IAAI,GAAG,MAAM,YAAY,CAC7B,IAAI,EACJ,EAAE,IAAI,EAAE,CACT,CAAC;YACF,MAAM,MAAM,GAAG,MAAM,kBAAkB,CAAC,IAAI,CAAC,CAAC;YAC9C,MAAM,IAAI,CAAC,GAAG,EAAE,CAAC;YACjB,OAAO;gBACL,QAAQ,EAAE,KAAK;gBACf,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;oBAC5B,OAAO;wBACL,KAAK,EAAE,KAAK;wBACZ,KAAK,EAAE,KAAK;qBACb,CAAC;gBACJ,CAAC,CAAC;aACH,CAAC;QACJ,CAAC,CAAA;KACF,CAAC;CACL,CAAC;AAGF,SAAgB,kBAAkB,CAAC,IAAwB;IACzD,IAAK,IAAI,IAAI,GAAG,EAAE,CAAC;QACjB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,mBAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AAClC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,49 @@
1
1
  {
2
2
  "name": "@divyacon/piece-mysql",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "DivyaCon mysql connector",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "require": "./dist/index.js",
11
+ "default": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "src",
17
+ "LICENSE.MIT-AP"
18
+ ],
19
+ "scripts": {
20
+ "build": "tsc -p tsconfig.json",
21
+ "vendor": "node ../scripts/vendor-ap.mjs piece-mysql"
22
+ },
23
+ "dependencies": {
24
+ "@agnocon/core-utils": "0.2.0",
25
+ "@agnocon/piece-types": "0.3.1",
26
+ "@agnocon/pieces-common": "0.12.8",
27
+ "@agnocon/pieces-framework": "0.36.0",
28
+ "tslib": "2.6.2",
29
+ "promise-mysql": "5.2.0",
30
+ "sqlstring": "2.3.3"
31
+ },
32
+ "devDependencies": {
33
+ "@types/node": "20.17.6",
34
+ "typescript": "5.5.4",
35
+ "@types/sqlstring": "2.3.2"
36
+ },
37
+ "license": "MIT",
38
+ "agnocon": {
39
+ "originVersion": "0.2.6"
40
+ },
41
+ "publishConfig": {
42
+ "access": "public",
43
+ "tag": "latest"
44
+ },
45
+ "keywords": [
46
+ "agnocon",
47
+ "connector"
48
+ ]
6
49
  }
package/src/index.ts ADDED
@@ -0,0 +1,52 @@
1
+ import {
2
+ PieceAuth,
3
+ Property,
4
+ createPiece,
5
+ } from '@agnocon/pieces-framework';
6
+ import { PieceCategory } from '@agnocon/pieces-framework';
7
+ import actions from './lib/actions';
8
+
9
+ export const mysqlAuth = PieceAuth.CustomAuth({
10
+ props: {
11
+ host: Property.ShortText({
12
+ displayName: 'Host',
13
+ required: true,
14
+ description: 'The hostname or address of the mysql server',
15
+ }),
16
+ port: Property.Number({
17
+ displayName: 'Port',
18
+ defaultValue: 3306,
19
+ description: 'The port to use for connecting to the mysql server',
20
+ required: true,
21
+ }),
22
+ user: Property.ShortText({
23
+ displayName: 'Username',
24
+ required: true,
25
+ description: 'The username to use for connecting to the mysql server',
26
+ }),
27
+ password: PieceAuth.SecretText({
28
+ displayName: 'Password',
29
+ description: 'The password to use to identify at the mysql server',
30
+ required: true,
31
+ }),
32
+ database: Property.ShortText({
33
+ displayName: 'Database',
34
+ description: 'The name of the database to use. Required if you are not using the "Execute Query" Action',
35
+ required: false,
36
+ }),
37
+ },
38
+ required: true,
39
+ });
40
+
41
+ export const mysql = createPiece({
42
+ displayName: 'MySQL',
43
+ description: "The world's most popular open-source database",
44
+
45
+ minimumSupportedRelease: '0.30.0',
46
+ logoUrl: 'https://cdn.activepieces.com/pieces/mysql.png',
47
+ categories: [PieceCategory.DEVELOPER_TOOLS],
48
+ authors: ["JanHolger","kishanprmr","khaledmashaly","abuaboud"],
49
+ auth: mysqlAuth,
50
+ actions,
51
+ triggers: [],
52
+ });
@@ -0,0 +1,41 @@
1
+ import { createAction, Property } from '@agnocon/pieces-framework';
2
+ import { mysqlCommon, mysqlConnect, sanitizeColumnName, warningMarkdown } from '../common';
3
+ import { mysqlAuth } from '../..';
4
+ import sqlstring from 'sqlstring';
5
+
6
+ export default createAction({
7
+ auth: mysqlAuth,
8
+ name: 'delete_row',
9
+ displayName: 'Delete Row',
10
+ description: 'Deletes one or more rows from a table',
11
+ audience: 'both',
12
+ aiMetadata: { description: 'Deletes every row in a MySQL table whose search column equals a given value. Use to remove records matched by a single column. Idempotent: once the matching rows are gone, re-running with the same input deletes nothing further.', idempotent: true },
13
+ props: {
14
+ markdown: warningMarkdown,
15
+ timezone: mysqlCommon.timezone,
16
+ table: mysqlCommon.table(),
17
+ search_column: Property.ShortText({
18
+ displayName: 'Search Column',
19
+ required: true,
20
+ }),
21
+ search_value: Property.ShortText({
22
+ displayName: 'Search Value',
23
+ required: true,
24
+ }),
25
+ },
26
+ async run(context) {
27
+ const tableName = sanitizeColumnName(context.propsValue.table);
28
+ const searchColumn = sanitizeColumnName(context.propsValue.search_column);
29
+ const searchValue = context.propsValue.search_value;
30
+
31
+ const queryString = `DELETE FROM ${tableName} WHERE ${searchColumn}=?;`;
32
+
33
+ const connection = await mysqlConnect(context.auth, context.propsValue);
34
+ try {
35
+ const result = await connection.query(queryString, [searchValue]);
36
+ return result;
37
+ } finally {
38
+ await connection.end();
39
+ }
40
+ },
41
+ });
@@ -0,0 +1,38 @@
1
+ import { createAction, Property } from '@agnocon/pieces-framework';
2
+ import { mysqlCommon, mysqlConnect, warningMarkdown } from '../common';
3
+ import { mysqlAuth } from '../..';
4
+
5
+ export default createAction({
6
+ auth: mysqlAuth,
7
+ name: 'execute_query',
8
+ displayName: 'Execute Query',
9
+ description: 'Executes a query on the mysql database and returns the results',
10
+ audience: 'both',
11
+ aiMetadata: { description: 'Runs an arbitrary SQL statement against the MySQL database and returns its results. Use as the escape hatch when the dedicated find/insert/update/delete actions cannot express the operation (joins, DDL, multi-table writes, aggregates). Pass dynamic values through the args array as ? placeholders to avoid SQL injection. Not idempotent in general: the effect and repeat-safety depend entirely on the SQL you supply (a SELECT is safe to repeat, an INSERT or UPDATE may not be).', idempotent: false },
12
+ props: {
13
+ markdown: warningMarkdown,
14
+ timezone: mysqlCommon.timezone,
15
+ query: Property.ShortText({
16
+ displayName: 'Query',
17
+ description: 'The query string to execute, use ? for arguments to avoid SQL injection.',
18
+ required: true,
19
+ }),
20
+ args: Property.Array({
21
+ displayName: 'Arguments',
22
+ description: 'Arguments to use in the query, if any. Should be in the same order as the ? in the query string..',
23
+ required: false,
24
+ }),
25
+ },
26
+ async run(context) {
27
+ const conn = await mysqlConnect(context.auth, context.propsValue);
28
+ try {
29
+ const results = await conn.query(
30
+ context.propsValue.query,
31
+ context.propsValue.args || []
32
+ );
33
+ return Array.isArray(results) ? { results } : results;
34
+ } finally {
35
+ await conn.end();
36
+ }
37
+ },
38
+ });
@@ -0,0 +1,49 @@
1
+ import { createAction, Property } from '@agnocon/pieces-framework';
2
+ import { mysqlCommon, mysqlConnect, sanitizeColumnName, warningMarkdown } from '../common';
3
+ import { mysqlAuth } from '../..';
4
+
5
+ export default createAction({
6
+ auth: mysqlAuth,
7
+ name: 'find_rows',
8
+ displayName: 'Find Rows',
9
+ description: 'Reads rows from a table',
10
+ audience: 'both',
11
+ aiMetadata: { description: 'Reads rows from a MySQL table that match a SQL WHERE condition, optionally limited to specific columns. Use to look up or filter records by arbitrary criteria. The condition is required and is interpolated raw into the query, so pass dynamic values through the args array (referenced as ? placeholders) to avoid SQL injection. Read-only and idempotent.', idempotent: true },
12
+ props: {
13
+ markdown: warningMarkdown,
14
+ timezone: mysqlCommon.timezone,
15
+ table: mysqlCommon.table(),
16
+ condition: Property.ShortText({
17
+ displayName: 'Condition',
18
+ description: 'SQL condition, can also include logic operators, etc.',
19
+ required: true,
20
+ }),
21
+ args: Property.Array({
22
+ displayName: 'Arguments',
23
+ description: 'Arguments can be used using ? in the condition',
24
+ required: false,
25
+ }),
26
+ columns: Property.Array({
27
+ displayName: 'Columns',
28
+ description: 'Specify the columns you want to select',
29
+ required: false,
30
+ }),
31
+ },
32
+ async run(context) {
33
+ const columns = (context.propsValue.columns as string[]) || ['*'];
34
+ const qsColumns = columns
35
+ .map((c) => sanitizeColumnName(c))
36
+ .join(',');
37
+
38
+ const qs = `SELECT ${qsColumns} FROM ${sanitizeColumnName(context.propsValue.table)} WHERE ${context.propsValue.condition};`;
39
+
40
+ const conn = await mysqlConnect(context.auth, context.propsValue);
41
+
42
+ try {
43
+ const results = await conn.query(qs, context.propsValue.args);
44
+ return { results };
45
+ } finally {
46
+ await conn.end();
47
+ }
48
+ },
49
+ });
@@ -0,0 +1,22 @@
1
+ import { createAction } from '@agnocon/pieces-framework';
2
+ import { mysqlConnect, mysqlGetTableNames } from '../common';
3
+ import { mysqlAuth } from '../..';
4
+
5
+ export default createAction({
6
+ auth: mysqlAuth,
7
+ name: 'get_tables',
8
+ displayName: 'Get Tables',
9
+ description: 'Returns a list of tables in the database',
10
+ audience: 'both',
11
+ aiMetadata: { description: 'Lists the names of all tables in the connected MySQL database (SHOW TABLES). Use to discover the schema before reading or writing rows. Takes no input; read-only and idempotent.', idempotent: true },
12
+ props: {},
13
+ async run(context) {
14
+ const conn = await mysqlConnect(context.auth, context.propsValue);
15
+ try {
16
+ const tables = await mysqlGetTableNames(conn);
17
+ return { tables };
18
+ } finally {
19
+ await conn.end();
20
+ }
21
+ },
22
+ });
@@ -0,0 +1,15 @@
1
+ import executeQuery from './execute-query';
2
+ import getTables from './get-tables';
3
+ import insertRow from './insert-row';
4
+ import updateRows from './update-row';
5
+ import deleteRows from './delete-row';
6
+ import selectRows from './find-rows';
7
+
8
+ export default [
9
+ selectRows,
10
+ insertRow,
11
+ updateRows,
12
+ deleteRows,
13
+ getTables,
14
+ executeQuery,
15
+ ];
@@ -0,0 +1,35 @@
1
+ import { createAction, Property } from '@agnocon/pieces-framework';
2
+ import { mysqlCommon, mysqlConnect, sanitizeColumnName, warningMarkdown } from '../common';
3
+ import { mysqlAuth } from '../..';
4
+ import sqlstring from 'sqlstring';
5
+
6
+ export default createAction({
7
+ auth: mysqlAuth,
8
+ name: 'insert_row',
9
+ displayName: 'Insert Row',
10
+ description: 'Inserts a new row into a table',
11
+ audience: 'both',
12
+ aiMetadata: { description: 'Inserts a new row into a MySQL table from a map of column names to values. Use to add a record. Not idempotent: each call performs a fresh INSERT, so repeating it adds duplicate rows (or errors on a unique-key collision).', idempotent: false },
13
+ props: {
14
+ timezone: mysqlCommon.timezone,
15
+ table: mysqlCommon.table(),
16
+ values: Property.Object({
17
+ displayName: 'Values',
18
+ required: true,
19
+ }),
20
+ },
21
+ async run(context) {
22
+ const fields = Object.keys(context.propsValue.values);
23
+ const qsFields = fields.map((f) => sanitizeColumnName(f)).join(',');
24
+ const qsValues = fields.map(() => '?').join(',');
25
+ const qs = `INSERT INTO ${sanitizeColumnName(context.propsValue.table)} (${qsFields}) VALUES (${qsValues});`;
26
+ const conn = await mysqlConnect(context.auth, context.propsValue);
27
+ try {
28
+ const values = fields.map((f) => context.propsValue.values[f]);
29
+ const result = await conn.query(qs, values);
30
+ return result;
31
+ } finally {
32
+ await conn.end();
33
+ }
34
+ },
35
+ });
@@ -0,0 +1,44 @@
1
+ import { createAction, Property } from '@agnocon/pieces-framework';
2
+ import { mysqlCommon, mysqlConnect, sanitizeColumnName } from '../common';
3
+ import { mysqlAuth } from '../..';
4
+
5
+ export default createAction({
6
+ auth: mysqlAuth,
7
+ name: 'update_row',
8
+ displayName: 'Update Row',
9
+ description: 'Updates one or more rows in a table',
10
+ audience: 'both',
11
+ aiMetadata: { description: 'Updates every row in a MySQL table whose search column equals a given value, setting the supplied column-to-value pairs. Use to modify existing records matched by a single column. Idempotent: re-running with the same input writes the same values and has no additional effect.', idempotent: true },
12
+ props: {
13
+ timezone: mysqlCommon.timezone,
14
+ table: mysqlCommon.table(),
15
+ values: Property.Object({
16
+ displayName: 'Values',
17
+ required: true,
18
+ }),
19
+ search_column: Property.ShortText({
20
+ displayName: 'Search Column',
21
+ required: true,
22
+ }),
23
+ search_value: Property.ShortText({
24
+ displayName: 'Search Value',
25
+ required: true,
26
+ }),
27
+ },
28
+ async run(context) {
29
+ const fields = Object.keys(context.propsValue.values);
30
+ const qsValues = fields.map((f) => sanitizeColumnName(f) + '=?').join(',');
31
+ const qs = `UPDATE ${sanitizeColumnName(context.propsValue.table)} SET ${qsValues} WHERE ${sanitizeColumnName(context.propsValue.search_column)}=?;`;
32
+ const conn = await mysqlConnect(context.auth, context.propsValue);
33
+ try {
34
+ const values = fields.map((f) => context.propsValue.values[f]);
35
+ const result = await conn.query(qs, [
36
+ ...values,
37
+ context.propsValue.search_value,
38
+ ]);
39
+ return result;
40
+ } finally {
41
+ await conn.end();
42
+ }
43
+ },
44
+ });
@@ -0,0 +1,83 @@
1
+ import {
2
+ AppConnectionValueForAuthProperty,
3
+ PiecePropValueSchema,
4
+ Property,
5
+ StaticPropsValue,
6
+ } from '@agnocon/pieces-framework';
7
+ import { Connection, createConnection } from 'promise-mysql';
8
+ import { mysqlAuth } from '../..';
9
+ import sqlstring from 'sqlstring';
10
+
11
+ export const warningMarkdown = Property.MarkDown({
12
+ value: `
13
+ **DO NOT** use dynamic input directly in the query string or column names.
14
+ \n
15
+ Use **?** in the query and dynamic values in args/values for parameterized queries to prevent **SQL injection**.`
16
+ });
17
+
18
+ export async function mysqlConnect(
19
+ auth: AppConnectionValueForAuthProperty<typeof mysqlAuth>,
20
+ propsValue: StaticPropsValue<any>
21
+ ): Promise<Connection> {
22
+ const conn = await createConnection({
23
+ host: auth.props.host,
24
+ port: auth.props.port || 3306,
25
+ user: auth.props.user,
26
+ password: auth.props.password,
27
+ database: auth.props.database || undefined,
28
+ timezone: propsValue.timezone,
29
+ });
30
+ return conn;
31
+ }
32
+
33
+ export async function mysqlGetTableNames(conn: Connection): Promise<string[]> {
34
+ const result = await conn.query('SHOW TABLES;');
35
+ return result.map((row: Record<string, string>) => row[Object.keys(row)[0]]);
36
+ }
37
+
38
+ export const mysqlCommon = {
39
+ timezone: Property.ShortText({
40
+ displayName: 'Timezone',
41
+ description: 'Timezone for the MySQL server to use',
42
+ required: false,
43
+ }),
44
+ table: (required = true) =>
45
+ Property.Dropdown({
46
+ auth: mysqlAuth,
47
+ displayName: 'Table',
48
+ required,
49
+ refreshers: [],
50
+ options: async ({ auth }) => {
51
+ if (!auth) {
52
+ return {
53
+ disabled: true,
54
+ placeholder: 'Connect to your database first',
55
+ options: [],
56
+ };
57
+ }
58
+ const conn = await mysqlConnect(
59
+ auth,
60
+ { auth }
61
+ );
62
+ const tables = await mysqlGetTableNames(conn);
63
+ await conn.end();
64
+ return {
65
+ disabled: false,
66
+ options: tables.map((table) => {
67
+ return {
68
+ label: table,
69
+ value: table,
70
+ };
71
+ }),
72
+ };
73
+ },
74
+ }),
75
+ };
76
+
77
+
78
+ export function sanitizeColumnName(name: string | undefined): string {
79
+ if ( name == '*') {
80
+ return name;
81
+ }
82
+ return sqlstring.escapeId(name);
83
+ }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.