Skip to main content

postgresql@3.4.2

Adaptor

Adaptor.execute

Kind: static class of Adaptor

new exports.execute(operations)

Execute a sequence of operations. Wraps language-common/execute, and prepends initial state for postgresql.

ParamTypeDescription
operationsOperationsOperations to be performed.

Example

execute(
create('foo'),
delete('bar')
)(state)

Adaptor.sql

Kind: static class of Adaptor
Access: public

new exports.sql(sqlQuery, options)

Execute an SQL statement

ParamTypeDescription
sqlQueryfunctiona function which takes state and returns a string of SQL.
optionsobjectOptional options argument

Example

sql(state => `select(*) from ${state.data.tableName};`, { writeSql: true })

Adaptor.findValue

Kind: static class of Adaptor
Access: public

new exports.findValue(filter)

Fetch a uuid key given a condition

ParamTypeDescription
filterobjectA filter object with the lookup table, a uuid and the condition

Example

findValue({
uuid: 'id',
relation: 'users',
where: { first_name: 'Mamadou' },
operator: { first_name: 'like' }
})

Adaptor.insert

Kind: static class of Adaptor
Access: public

new exports.insert(table, record, options)

Insert a record

ParamTypeDescription
tablestringThe target table
recordobjectPayload data for the record as a JS object or function
optionsobjectOptional options argument

Example

insert('users', { name: 'Elodie', id: 7 }, { setNull: "'NaN'", logValues: true });

Adaptor.insertMany

Kind: static class of Adaptor
Access: public

new exports.insertMany(table, records, options)

Insert many records, using the keys of the first as the column template

ParamTypeDescription
tablestringThe target table
recordsarrayAn array or a function that takes state and returns an array
optionsobjectOptional options argument

Example

insertMany('users', state => state.data.recordArray, { setNull: "'undefined'", logValues: true });

Adaptor.upsert

Kind: static class of Adaptor
Access: public

new exports.upsert(table, uuid, record, options)

Insert or update a record using ON CONFLICT UPDATE

ParamTypeDescription
tablestringThe target table
uuidstringThe uuid column to determine a matching/existing record
recordobjectPayload data for the record as a JS object or function
optionsobjectOptional options argument

Example

upsert(
'users', // the DB table
'ON CONSTRAINT users_pkey', // a DB column with a unique constraint OR a CONSTRAINT NAME
{ name: 'Elodie', id: 7 },
{ setNull: ["''", "'undefined'"], writeSql:true, execute: true, logValues: true }
)

Adaptor.upsertIf

Kind: static class of Adaptor
Access: public

new exports.upsertIf(logical, table, uuid, record, options)

Insert or update a record based on a logical condition using ON CONFLICT UPDATE

ParamTypeDescription
logicalstringa data to check existing value for.
tablestringThe target table
uuidstringThe uuid column to determine a matching/existing record
recordobjectPayload data for the record as a JS object or function
optionsobjectOptional options argument

Example

upsertIf(
dataValue('name'),
'users', // the DB table
'ON CONSTRAINT users_pkey', // a DB column with a unique constraint OR a CONSTRAINT NAME
{ name: 'Elodie', id: 7 },
{ writeSql:true, execute: true }
)

Adaptor.upsertMany

Kind: static class of Adaptor
Access: public

new exports.upsertMany(table, uuid, data, options)

Insert or update multiple records using ON CONFLICT UPDATE and excluded

ParamTypeDescription
tablestringThe target table
uuidstringThe uuid column to determine a matching/existing record
dataarrayAn array of objects or a function that returns an array
optionsobjectOptional options argument

Example

upsertMany(
'users', // the DB table
'email', // a DB column with a unique constraint OR a CONSTRAINT NAME
[
{ name: 'one', email: 'one@openfn.org },
{ name: 'two', email: 'two@openfn.org },
]
{ logValues: true }
)

Adaptor.describeTable

Kind: static class of Adaptor
Access: public

new exports.describeTable(tableName, options)

List the columns of a table in a database.

ParamTypeDescription
tableNamestringThe name of the table to describe
optionsobjectOptional options argument

Example

describeTable('clinic_visits')

Adaptor.insertTable

Kind: static class of Adaptor
Access: public

new exports.insertTable(tableName, columns, options)

Create a table in database when given an array of columns and a table_name.

ParamTypeDescription
tableNamestringThe name of the table to create
columnsarrayAn array of form columns
optionsobjectOptional options argument

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
})
));

Adaptor.modifyTable

Kind: static class of Adaptor
Access: public

new exports.modifyTable(tableName, columns, options)

Alter an existing table in the database.

ParamTypeDescription
tableNamestringThe name of the table to alter
columnsarrayAn array of form columns
optionsobjectOptional options argument

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
})
));