/** * Execute a sequence of operations. * Wraps `language-common/execute`, and prepends initial state for mssql. * @example * execute( * create('foo'), * delete('bar') * )(state) * @private * @param {Operations} operations - Operations to be performed. * @returns {Operation} */ export function execute(...operations: Operations): Operation; /** * Execute a raw SQL statement * @public * @example * sql({ * query: 'SELECT * FROM users WHERE id = @id', * options * }) * @function * @param {object} params - Payload data for the SQL query * @param {string} params.query - The SQL query to execute * @param {object} [params.options] - Optional query options * @returns {Operation} */ export function sql(params: { query: string; options?: object; }): Operation; /** * Fetch a uuid key given a condition * @public * @example * findValue({ * uuid: 'id', * relation: 'users', * where: { first_name: 'Mama%', last_name: 'Cisse'}, * operator: { first_name: 'like', last_name: '='} * }) * @function * @param {object} filter - A filter object with the lookup table, a uuid and the condition * @param {string} filter.uuid - The uuid column to determine a matching/existing record * @param {string} filter.relation - The table to lookup the value in * @param {object} filter.where - The condition to use for the lookup. Values are automatically escaped for security. * @param {object} filter.operator - The operator to use for the lookup * @returns {Operation} */ export function findValue(filter: { uuid: string; relation: string; where: object; operator: object; }): Operation; /** * Insert a record * @public * @example * insert(table, record, {setNull: ["'undefined'", "''"], logValues: false}) * @function * @param {string} table - The target table * @param {object} record - Payload data for the record as a JS object * @param {object} options - Optional options argument * @returns {Operation} */ export function insert(table: string, record: object, options: object): Operation; /** * Insert many records, using the keys of the first as the column template * @public * @example * insertMany(table, records, { setNull: false, writeSql: true, logValues: false }) * @function * @param {string} table - The target table * @param {function} records - A function that takes state and returns an array of records * @param {object} options - Optional options argument * @returns {Operation} */ export function insertMany(table: string, records: Function, options: object): Operation; /** * Insert or update a record using SQL MERGE * @public * @example * upsert(table, uuid, record, { setNull: "'undefined'", logValues: false}) * upsert(table, [uuid1, uuid2], record, { setNull: "'undefined'", logValues: false}) * @function * @param {string} table - The target table * @param {string} uuid - The uuid column to determine a matching/existing record * @param {object} record - Payload data for the record as a JS object * @param {object} options - Optional options argument * @returns {Operation} */ export function upsert(table: string, uuid: string, record: object, options: object): Operation; /** * Insert or update a record based on a logical condition using ON CONFLICT UPDATE * @public * @example * upsertIf( * dataValue('name'), * 'users', // the DB table * 'uuid', // a DB column with a unique constraint * { name: 'Elodie', id: 7 }, * { writeSql:true, execute: true, logValues: false } * ) * @function * @param {string} logical - a data to check existing value for. * @param {string} table - The target table * @param {string} uuid - The uuid column to determine a matching/existing record * @param {object} record - Payload data for the record as a JS object or function * @param {object} options - Optional options argument * @returns {Operation} */ export function upsertIf(logical: string, table: string, uuid: string, record: object, options: object): Operation; /** * Insert or update multiple records using ON CONFLICT UPDATE and excluded * @public * @example * upsertMany( * 'users', 'email', records, { logValues: false } * ) * upsertMany( * 'users', ['email', 'phone'], records, { logValues: false } * ) * @function * @param {string} table - The target table * @param {string} uuid - The uuid column to determine a matching/existing record * @param {function} records - A function that takes state and returns an array of records * @param {object} options - Optional options argument * @returns {Operation} */ export function upsertMany(table: string, uuid: string, records: Function, options: object): Operation; /** * List the columns of a table in a database. * @public * @example * describeTable('clinic_visits') * @function * @param {string} tableName - The name of the table to describe * @param {object} options - Optional options argument * @returns {Operation} */ export function describeTable(tableName: string, options: object): Operation; /** * Create a table in database when given an array of columns and a table_name. * @public * @example * insertTable('table_name', state => state.data.map( * column => ({ * name: column.name, * type: column.type, * required: true, // optional * unique: false, // optional - to be set to true for unique constraint * }) * )); * @function * @param {string} tableName - The name of the table to create * @param {array} columns - An array of form columns * @param {object} options - Optional options argument * @returns {Operation} */ export function insertTable(tableName: string, columns: any[], options: object): Operation; /** * Alter an existing table in the database. * @public * @example * modifyTable('table_name', state => state.data.map( * newColumn => ({ * name: newColumn.name, * type: newColumn.type, * required: true, // optional * unique: false, // optional - to be set to true for unique constraint * }) * )); * @function * @param {string} tableName - The name of the table to alter * @param {array} columns - An array of form columns * @param {object} options - Optional options argument * @returns {Operation} */ export function modifyTable(tableName: string, columns: any[], options: object): Operation; export { alterState, as, combine, cursor, dataPath, dataValue, dateFns, each, field, fields, fn, fnIf, lastReferenceValue, log, merge, sourceValue } from "@openfn/language-common";