mysql@4.0.1
This adaptor exports the following from common:
- alterState
- arrayToString()
- as()
- assert()
- combine()
- cursor()
- dataPath()
- dataValue()
- dateFns
- each()
- field()
- fields()
- fn()
- fnIf()
- lastReferenceValue()
- merge()
- sourceValue()
Functions
insert
insert(table, fields) ⇒ Operation
Insert a record
| Param | Type | Description |
|---|---|---|
| table | string | The target table |
| fields | object | A fields object |
This operation writes the following keys to state:
| State Key | Description |
|---|---|
| data | the query results object |
| data.result | the query result rows |
| data.fields | the query result fields |
| queries | an array of queries executed. Queries are added if options.writeSql is true. |
| references | an array of all previous data objects used in the Job |
Example: Insert a record into a table
insert("users", { name: "one", email: "one@openfn.org" });
sql
sql(sqlQuery, [options]) ⇒ Operation
Execute a SQL statement. Take care when inserting values from state directly into a query, as this can be a vector for injection attacks. See OWASP SQL Injection Prevention Cheat Sheet for guidelines
| Param | Type | Description |
|---|---|---|
| sqlQuery | string | The sql query string. |
| [options] | sqlOptions | The sql query options. |
This operation writes the following keys to state:
| State Key | Description |
|---|---|
| data | the query results object |
| data.result | the query result rows |
| data.fields | the query result fields |
| queries | an array of queries executed. Queries are added if options.writeSql is true. |
| references | an array of all previous data objects used in the Job |
Example
sql(state => `select * from ${state.data.tableName};`, { writeSql: true })
Example: Prepared statements
sql(state => `select * from ?? where id = ?;`, {
values: state => [state.data.tableName, state.data.id],
});
upsert
upsert(table, fields) ⇒ Operation
Insert or Update a record if matched
| Param | Type | Description |
|---|---|---|
| table | string | The target table |
| fields | object | A fields object |
This operation writes the following keys to state:
| State Key | Description |
|---|---|
| data | the query results object |
| data.result | the query result rows |
| data.fields | the query result fields |
| queries | an array of queries executed. Queries are added if options.writeSql is true. |
| references | an array of all previous data objects used in the Job |
Example: Upsert a record into a table
upsert("users", { name: "Tuchi Dev" });
upsertMany
upsertMany(table, data) ⇒ Operation
Insert or update multiple records using ON DUPLICATE KEY
| Param | Type | Description |
|---|---|---|
| table | string | The target table |
| data | array | An array of objects fields |
This operation writes the following keys to state:
| State Key | Description |
|---|---|
| data | the query results object |
| data.result | the query result rows |
| data.fields | the query result fields |
| queries | an array of queries executed. Queries are added if options.writeSql is true. |
| references | an array of all previous data objects used in the Job |
Interfaces
sqlOptions
Properties
| Name | Type | Default | Description |
|---|---|---|---|
| [values] | array | An array of values for prepared statements. | |
| [writeSql] | boolean | false | If true, logs the generated SQL statement. Defaults to false. |
| [execute] | boolean | true | If false, does not execute the SQL, just logs it and adds to state.queries. Defaults to true. |