Skip to main content

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

ParamTypeDescription
tablestringThe target table
fieldsobjectA 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

ParamTypeDescription
optionsobjectPayload data for the message

Example: Execute a SQL statement

query({ sql: 'select * from users;' })

sqlString

sqlString(queryString) ⇒ Operation

Execute a SQL statement

ParamTypeDescription
queryStringStringA 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

ParamTypeDescription
tablestringThe target table
fieldsobjectA 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

ParamTypeDescription
tablestringThe target table
dataarrayAn 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' },
]
)