mysql@2.1.1
- insert(table, fields)
- query(options)
- sqlString(queryString)
- upsert(table, fields)
- upsertMany(table, data)
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 });
query
query(options) ⇒ Operation
Execute a SQL statement
Param | Type | Description |
---|---|---|
options | object | Payload data for the message |
Example: Execute a SQL statement
query({ sql: 'select * from users;' })
sqlString
sqlString(queryString) ⇒ Operation
Execute a SQL statement
Param | Type | Description |
---|---|---|
queryString | String | A query string (or function which takes state and returns a string) |
Example: Execute a SQL statement
sqlString(state => "select * from items;")
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' },
]
)