Skip to main content

mssql@5.0.4

describeTable(tableName, options)
findValue(filter)
insert(table, record, options)
insertMany(table, records, options)
insertTable(tableName, columns, options)
modifyTable(tableName, columns, options)
sql(params)
upsert(table, uuid, record, options)
upsertIf(logical, table, uuid, record, options)
upsertMany(table, uuid, records, options)

This adaptor exports the following from common:

alterState()
combine()
cursor()
dataPath()
dataValue()
dateFns
each()
field()
fields()
fn()
fnIf()
http
lastReferenceValue()
merge()
sourceValue()

Functions

describeTable

describeTable(tableName, options) ⇒ Operation

List the columns of a table in a database.

ParamTypeDescription
tableNamestringThe name of the table to describe
optionsobjectOptional options argument

Example

describeTable('clinic_visits')

findValue

findValue(filter) ⇒ Operation

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: 'Mama%', last_name: 'Cisse'},
operator: { first_name: 'like', last_name: '='}
})

insert

insert(table, record, options) ⇒ Operation

Insert a record

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

Example

insert(table, record, {setNull: ["'undefined'", "''"], logValues: false})

insertMany

insertMany(table, records, options) ⇒ Operation

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

ParamTypeDescription
tablestringThe target table
recordsfunctionA function that takes state and returns an array of records
optionsobjectOptional options argument

Example

insertMany(table, records, { setNull: false, writeSql: true, logValues: false })

insertTable

insertTable(tableName, columns, options) ⇒ Operation

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

modifyTable

modifyTable(tableName, columns, options) ⇒ Operation

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

sql

sql(params) ⇒ Operation

Execute an SQL statement

ParamTypeDescription
paramsobjectPayload data for the message

Example

sql({ query, options })

upsert

upsert(table, uuid, record, options) ⇒ Operation

Insert or update a record using SQL MERGE

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

Example

upsert(table, uuid, record, { setNull: "'undefined'", logValues: false})
upsert(table, [uuid1, uuid2], record, { setNull: "'undefined'", logValues: false})

upsertIf

upsertIf(logical, table, uuid, record, options) ⇒ Operation

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
'uuid', // a DB column with a unique constraint
{ name: 'Elodie', id: 7 },
{ writeSql:true, execute: true, logValues: false }
)

upsertMany

upsertMany(table, uuid, records, options) ⇒ Operation

Insert or update multiple records using ON CONFLICT UPDATE and excluded

ParamTypeDescription
tablestringThe target table
uuidstringThe uuid column to determine a matching/existing record
recordsfunctionA function that takes state and returns an array of records
optionsobjectOptional options argument

Example

upsertMany(
'users', 'email', records, { logValues: false }
)
upsertMany(
'users', ['email', 'phone'], records, { logValues: false }
)