mysql@3.0.0
This adaptor exports the following from common:
- alterState()
- arrayToString()
- as()
- 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 |
Example: Insert a record into the users
table
insert("users", { name: (state) => state.data.name });
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 | Default | Description |
---|---|---|---|
sqlQuery | string | function | The SQL query as a string or a function that returns a string using state. | |
[options] | object | Optional options argument. | |
[options.writeSql] | boolean | false | If true, logs the generated SQL statement. Defaults to false. |
[options.execute] | boolean | true | If false, does not execute the SQL, just logs it and adds to state.queries. Defaults to true. |
Example
sql(state => `select * from ${state.data.tableName};`, { writeSql: true })
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 |
Example: Upsert a record
upsert("table", { name: (state) => state.data.name });
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 or a function that returns an array |
Example: Upsert multiple records
upsertMany(
'users', // the DB table
[
{ name: 'one', email: 'one@openfn.org' },
{ name: 'two', email: 'two@openfn.org' },
]
)