@openfn/language-mysql 2.0.8 → 2.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.
- package/ast.json +96 -5
- package/dist/index.cjs +6 -0
- package/dist/index.js +14 -8
- package/package.json +1 -2
- package/types/Adaptor.d.ts +10 -27
package/ast.json
CHANGED
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
"tags": [
|
|
12
12
|
{
|
|
13
13
|
"title": "example",
|
|
14
|
-
"description": "
|
|
14
|
+
"description": "insert(\"users\", { name: (state) => state.data.name });",
|
|
15
|
+
"caption": "Insert a record into the `users` table"
|
|
15
16
|
},
|
|
16
17
|
{
|
|
17
18
|
"title": "function",
|
|
@@ -64,7 +65,8 @@
|
|
|
64
65
|
"tags": [
|
|
65
66
|
{
|
|
66
67
|
"title": "example",
|
|
67
|
-
"description": "
|
|
68
|
+
"description": "upsert(\"table\", { name: (state) => state.data.name });",
|
|
69
|
+
"caption": "Upsert a record"
|
|
68
70
|
},
|
|
69
71
|
{
|
|
70
72
|
"title": "function",
|
|
@@ -122,7 +124,8 @@
|
|
|
122
124
|
},
|
|
123
125
|
{
|
|
124
126
|
"title": "example",
|
|
125
|
-
"description": "upsertMany(\n 'users', // the DB table\n [\n { name: 'one', email: 'one@openfn.org' },\n { name: 'two', email: 'two@openfn.org' },\n ]\n)"
|
|
127
|
+
"description": "upsertMany(\n 'users', // the DB table\n [\n { name: 'one', email: 'one@openfn.org' },\n { name: 'two', email: 'two@openfn.org' },\n ]\n)",
|
|
128
|
+
"caption": "Upsert multiple records"
|
|
126
129
|
},
|
|
127
130
|
{
|
|
128
131
|
"title": "function",
|
|
@@ -174,7 +177,8 @@
|
|
|
174
177
|
"tags": [
|
|
175
178
|
{
|
|
176
179
|
"title": "example",
|
|
177
|
-
"description": "
|
|
180
|
+
"description": "query({ sql: 'select * from users;' })",
|
|
181
|
+
"caption": "Execute a SQL statement"
|
|
178
182
|
},
|
|
179
183
|
{
|
|
180
184
|
"title": "function",
|
|
@@ -217,7 +221,8 @@
|
|
|
217
221
|
"tags": [
|
|
218
222
|
{
|
|
219
223
|
"title": "example",
|
|
220
|
-
"description": "
|
|
224
|
+
"description": "sqlString(state => \"select * from items;\")",
|
|
225
|
+
"caption": "Execute a SQL statement"
|
|
221
226
|
},
|
|
222
227
|
{
|
|
223
228
|
"title": "function",
|
|
@@ -834,6 +839,92 @@
|
|
|
834
839
|
]
|
|
835
840
|
},
|
|
836
841
|
"valid": true
|
|
842
|
+
},
|
|
843
|
+
{
|
|
844
|
+
"name": "cursor",
|
|
845
|
+
"params": [
|
|
846
|
+
"value",
|
|
847
|
+
"options"
|
|
848
|
+
],
|
|
849
|
+
"docs": {
|
|
850
|
+
"description": "Sets a cursor property on state.\nSupports natural language dates like `now`, `today`, `yesterday`, `n hours ago`, `n days ago`, and `start`,\nwhich will be converted relative to the environment (ie, the Lightning or CLI locale). Custom timezones\nare not yet supported.\nYou can provide a formatter to customise the final cursor value, which is useful for normalising\ndifferent inputs. The custom formatter runs after natural language date conversion.\nSee the usage guide at {@link https://docs.openfn.org/documentation/jobs/job-writing-guide#using-cursors}",
|
|
851
|
+
"tags": [
|
|
852
|
+
{
|
|
853
|
+
"title": "public",
|
|
854
|
+
"description": null,
|
|
855
|
+
"type": null
|
|
856
|
+
},
|
|
857
|
+
{
|
|
858
|
+
"title": "function",
|
|
859
|
+
"description": null,
|
|
860
|
+
"name": null
|
|
861
|
+
},
|
|
862
|
+
{
|
|
863
|
+
"title": "example",
|
|
864
|
+
"description": "cursor($.cursor, { defaultValue: 'today' })",
|
|
865
|
+
"caption": "Use a cursor from state if present, or else use the default value"
|
|
866
|
+
},
|
|
867
|
+
{
|
|
868
|
+
"title": "example",
|
|
869
|
+
"description": "cursor(22)",
|
|
870
|
+
"caption": "Use a pagination cursor"
|
|
871
|
+
},
|
|
872
|
+
{
|
|
873
|
+
"title": "param",
|
|
874
|
+
"description": "the cursor value. Usually an ISO date, natural language date, or page number",
|
|
875
|
+
"type": {
|
|
876
|
+
"type": "NameExpression",
|
|
877
|
+
"name": "any"
|
|
878
|
+
},
|
|
879
|
+
"name": "value"
|
|
880
|
+
},
|
|
881
|
+
{
|
|
882
|
+
"title": "param",
|
|
883
|
+
"description": "options to control the cursor.",
|
|
884
|
+
"type": {
|
|
885
|
+
"type": "NameExpression",
|
|
886
|
+
"name": "object"
|
|
887
|
+
},
|
|
888
|
+
"name": "options"
|
|
889
|
+
},
|
|
890
|
+
{
|
|
891
|
+
"title": "param",
|
|
892
|
+
"description": "set the cursor key. Will persist through the whole run.",
|
|
893
|
+
"type": {
|
|
894
|
+
"type": "NameExpression",
|
|
895
|
+
"name": "string"
|
|
896
|
+
},
|
|
897
|
+
"name": "options.key"
|
|
898
|
+
},
|
|
899
|
+
{
|
|
900
|
+
"title": "param",
|
|
901
|
+
"description": "the value to use if value is falsy",
|
|
902
|
+
"type": {
|
|
903
|
+
"type": "NameExpression",
|
|
904
|
+
"name": "any"
|
|
905
|
+
},
|
|
906
|
+
"name": "options.defaultValue"
|
|
907
|
+
},
|
|
908
|
+
{
|
|
909
|
+
"title": "param",
|
|
910
|
+
"description": "custom formatter for the final cursor value",
|
|
911
|
+
"type": {
|
|
912
|
+
"type": "NameExpression",
|
|
913
|
+
"name": "Function"
|
|
914
|
+
},
|
|
915
|
+
"name": "options.format"
|
|
916
|
+
},
|
|
917
|
+
{
|
|
918
|
+
"title": "returns",
|
|
919
|
+
"description": null,
|
|
920
|
+
"type": {
|
|
921
|
+
"type": "NameExpression",
|
|
922
|
+
"name": "Operation"
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
]
|
|
926
|
+
},
|
|
927
|
+
"valid": false
|
|
837
928
|
}
|
|
838
929
|
]
|
|
839
930
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -28,8 +28,10 @@ __export(src_exports, {
|
|
|
28
28
|
alterState: () => import_language_common2.alterState,
|
|
29
29
|
arrayToString: () => import_language_common2.arrayToString,
|
|
30
30
|
combine: () => import_language_common2.combine,
|
|
31
|
+
cursor: () => import_language_common2.cursor,
|
|
31
32
|
dataPath: () => import_language_common2.dataPath,
|
|
32
33
|
dataValue: () => import_language_common2.dataValue,
|
|
34
|
+
dateFns: () => import_language_common2.dateFns,
|
|
33
35
|
default: () => src_default,
|
|
34
36
|
each: () => import_language_common2.each,
|
|
35
37
|
execute: () => execute,
|
|
@@ -55,8 +57,10 @@ __export(Adaptor_exports, {
|
|
|
55
57
|
alterState: () => import_language_common2.alterState,
|
|
56
58
|
arrayToString: () => import_language_common2.arrayToString,
|
|
57
59
|
combine: () => import_language_common2.combine,
|
|
60
|
+
cursor: () => import_language_common2.cursor,
|
|
58
61
|
dataPath: () => import_language_common2.dataPath,
|
|
59
62
|
dataValue: () => import_language_common2.dataValue,
|
|
63
|
+
dateFns: () => import_language_common2.dateFns,
|
|
60
64
|
each: () => import_language_common2.each,
|
|
61
65
|
execute: () => execute,
|
|
62
66
|
field: () => import_language_common2.field,
|
|
@@ -253,8 +257,10 @@ var src_default = Adaptor_exports;
|
|
|
253
257
|
alterState,
|
|
254
258
|
arrayToString,
|
|
255
259
|
combine,
|
|
260
|
+
cursor,
|
|
256
261
|
dataPath,
|
|
257
262
|
dataValue,
|
|
263
|
+
dateFns,
|
|
258
264
|
each,
|
|
259
265
|
execute,
|
|
260
266
|
field,
|
package/dist/index.js
CHANGED
|
@@ -10,8 +10,10 @@ __export(Adaptor_exports, {
|
|
|
10
10
|
alterState: () => alterState,
|
|
11
11
|
arrayToString: () => arrayToString,
|
|
12
12
|
combine: () => combine,
|
|
13
|
+
cursor: () => cursor,
|
|
13
14
|
dataPath: () => dataPath,
|
|
14
15
|
dataValue: () => dataValue,
|
|
16
|
+
dateFns: () => dateFns,
|
|
15
17
|
each: () => each,
|
|
16
18
|
execute: () => execute,
|
|
17
19
|
field: () => field,
|
|
@@ -35,20 +37,22 @@ import {
|
|
|
35
37
|
import mysql from "mysql";
|
|
36
38
|
import squel from "squel";
|
|
37
39
|
import {
|
|
38
|
-
field,
|
|
39
|
-
fields,
|
|
40
|
-
sourceValue,
|
|
41
|
-
alterState,
|
|
42
40
|
fn,
|
|
43
41
|
fnIf,
|
|
44
|
-
arrayToString,
|
|
45
42
|
each,
|
|
46
|
-
|
|
43
|
+
http,
|
|
47
44
|
merge,
|
|
45
|
+
field,
|
|
46
|
+
fields,
|
|
47
|
+
cursor,
|
|
48
|
+
dateFns,
|
|
49
|
+
combine,
|
|
48
50
|
dataPath,
|
|
49
51
|
dataValue,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
+
alterState,
|
|
53
|
+
sourceValue,
|
|
54
|
+
arrayToString,
|
|
55
|
+
lastReferenceValue
|
|
52
56
|
} from "@openfn/language-common";
|
|
53
57
|
function execute(...operations) {
|
|
54
58
|
const initialState = {
|
|
@@ -225,8 +229,10 @@ export {
|
|
|
225
229
|
alterState,
|
|
226
230
|
arrayToString,
|
|
227
231
|
combine,
|
|
232
|
+
cursor,
|
|
228
233
|
dataPath,
|
|
229
234
|
dataValue,
|
|
235
|
+
dateFns,
|
|
230
236
|
src_default as default,
|
|
231
237
|
each,
|
|
232
238
|
execute,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfn/language-mysql",
|
|
3
|
-
"version": "2.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "A MySQL Language Pack for OpenFn",
|
|
5
5
|
"homepage": "https://docs.openfn.org",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -24,7 +24,6 @@
|
|
|
24
24
|
"@openfn/language-common": "2.3.0"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@openfn/simple-ast": "^0.4.1",
|
|
28
27
|
"assertion-error": "^1.0.1",
|
|
29
28
|
"chai": "^3.4.0",
|
|
30
29
|
"deep-eql": "^0.1.3",
|
package/types/Adaptor.d.ts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Execute a sequence of operations.
|
|
3
3
|
* Wraps `language-common/execute`, and prepends initial state for mysql.
|
|
4
|
-
* @example
|
|
5
|
-
* execute(
|
|
6
|
-
* create('foo'),
|
|
7
|
-
* delete('bar')
|
|
8
|
-
* )(state)
|
|
9
4
|
* @private
|
|
10
5
|
* @param {Operations} operations - Operations to be performed.
|
|
11
6
|
* @returns {Operation}
|
|
@@ -13,12 +8,8 @@
|
|
|
13
8
|
export function execute(...operations: Operations): Operation;
|
|
14
9
|
/**
|
|
15
10
|
* Insert a record
|
|
16
|
-
* @example
|
|
17
|
-
*
|
|
18
|
-
* insert('table', fields(
|
|
19
|
-
* field('name', dataValue('name'))
|
|
20
|
-
* ))
|
|
21
|
-
* )(state)
|
|
11
|
+
* @example <caption>Insert a record into the `users` table</caption>
|
|
12
|
+
* insert("users", { name: (state) => state.data.name });
|
|
22
13
|
* @function
|
|
23
14
|
* @public
|
|
24
15
|
* @param {string} table - The target table
|
|
@@ -28,12 +19,8 @@ export function execute(...operations: Operations): Operation;
|
|
|
28
19
|
export function insert(table: string, fields: object): Operation;
|
|
29
20
|
/**
|
|
30
21
|
* Insert or Update a record if matched
|
|
31
|
-
* @example
|
|
32
|
-
*
|
|
33
|
-
* upsert('table', fields(
|
|
34
|
-
* field('name', dataValue('name'))
|
|
35
|
-
* ))
|
|
36
|
-
* )(state)
|
|
22
|
+
* @example <caption>Upsert a record</caption>
|
|
23
|
+
* upsert("table", { name: (state) => state.data.name });
|
|
37
24
|
* @function
|
|
38
25
|
* @public
|
|
39
26
|
* @param {string} table - The target table
|
|
@@ -44,7 +31,7 @@ export function upsert(table: string, fields: object): Operation;
|
|
|
44
31
|
/**
|
|
45
32
|
* Insert or update multiple records using ON DUPLICATE KEY
|
|
46
33
|
* @public
|
|
47
|
-
* @example
|
|
34
|
+
* @example <caption>Upsert multiple records</caption>
|
|
48
35
|
* upsertMany(
|
|
49
36
|
* 'users', // the DB table
|
|
50
37
|
* [
|
|
@@ -61,10 +48,8 @@ export function upsert(table: string, fields: object): Operation;
|
|
|
61
48
|
export function upsertMany(table: string, data: any[]): Operation;
|
|
62
49
|
/**
|
|
63
50
|
* Execute a SQL statement
|
|
64
|
-
* @example
|
|
65
|
-
*
|
|
66
|
-
* query({ sql: 'select * from users;' })
|
|
67
|
-
* )(state)
|
|
51
|
+
* @example <caption>Execute a SQL statement</caption>
|
|
52
|
+
* query({ sql: 'select * from users;' })
|
|
68
53
|
* @function
|
|
69
54
|
* @public
|
|
70
55
|
* @param {object} options - Payload data for the message
|
|
@@ -73,14 +58,12 @@ export function upsertMany(table: string, data: any[]): Operation;
|
|
|
73
58
|
export function query(options: object): Operation;
|
|
74
59
|
/**
|
|
75
60
|
* Execute a SQL statement
|
|
76
|
-
* @example
|
|
77
|
-
*
|
|
78
|
-
* sqlString(state => "select * from items;")
|
|
79
|
-
* )(state)
|
|
61
|
+
* @example <caption>Execute a SQL statement</caption>
|
|
62
|
+
* sqlString(state => "select * from items;")
|
|
80
63
|
* @function
|
|
81
64
|
* @public
|
|
82
65
|
* @param {String} queryString - A query string (or function which takes state and returns a string)
|
|
83
66
|
* @returns {Operation}
|
|
84
67
|
*/
|
|
85
68
|
export function sqlString(queryString: string): Operation;
|
|
86
|
-
export {
|
|
69
|
+
export { fn, fnIf, each, http, merge, field, fields, cursor, dateFns, combine, dataPath, dataValue, alterState, sourceValue, arrayToString, lastReferenceValue } from "@openfn/language-common";
|