export function setMockConnection(mockConnection: any): void; /** * State object * @typedef {Object} MySQLState * @property data - the query results object * @property data.result - the query result rows * @property data.fields - the query result fields * @property queries - an array of queries executed. Queries are added if `options.writeSql` is true. * @property references - an array of all previous data objects used in the Job * @private **/ /** * @typedef {Object} sqlOptions * @property {array} [values] - An array of values for prepared statements. * @property {boolean} [writeSql = false] - If true, logs the generated SQL statement. Defaults to false. * @property {boolean} [execute = true] - If false, does not execute the SQL, just logs it and adds to state.queries. Defaults to true. * */ /** * Execute a sequence of operations. * Wraps `language-common/execute`, and prepends initial state for mysql. * @private * @param {Operations} operations - Operations to be performed. * @returns {Operation} */ export function execute(...operations: Operations): 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](https://cheatsheetseries.owasp.org/cheatsheets/SQL_Injection_Prevention_Cheat_Sheet.html) * for guidelines * @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], * }); * @function * @public * @param {string} sqlQuery - The sql query string. * @param {sqlOptions} [options] - The sql query options. * @state {MySQLState} * @returns {Operation} */ export function sql(sqlQuery: string, options?: sqlOptions): Operation; /** * Insert a record * @example Insert a record into a table * insert("users", { name: "one", email: "one@openfn.org" }); * @function * @public * @param {string} table - The target table * @param {object} fields - A fields object * @state {MySQLState} * @returns {Operation} */ export function insert(table: string, fields: object): Operation; /** * Insert or Update a record if matched * @example Upsert a record into a table * upsert("users", { name: "Tuchi Dev" }); * @function * @public * @param {string} table - The target table * @param {object} fields - A fields object * @state {MySQLState} * @returns {Operation} */ export function upsert(table: string, fields: object): Operation; /** * Insert or update multiple records using ON DUPLICATE KEY * @public * @exampleUpsert multiple records into a table * upsertMany( * "users", // the DB table * [ * { name: "one", email: "one@openfn.org" }, * { name: "two", email: "two@openfn.org" }, * ] * ); * @function * @public * @param {string} table - The target table * @param {array} data - An array of objects fields * @state {MySQLState} * @returns {Operation} */ export function upsertMany(table: string, data: any[]): Operation; /** * State object */ export type MySQLState = { /** * - the query results object */ data: any; /** * - the query result rows */ result: any; /** * - the query result fields */ fields: any; /** * - an array of queries executed. Queries are added if `options.writeSql` is true. */ queries: any; /** * - an array of all previous data objects used in the Job */ references: any; }; export type sqlOptions = { /** * - An array of values for prepared statements. */ values?: any[]; /** * - If true, logs the generated SQL statement. Defaults to false. */ writeSql?: boolean; /** * - If false, does not execute the SQL, just logs it and adds to state.queries. Defaults to true. */ execute?: boolean; }; export { fn, fnIf, each, merge, field, fields, assert, cursor, dateFns, combine, dataPath, dataValue, alterState, sourceValue, arrayToString, lastReferenceValue, as } from "@openfn/language-common";