mssql@5.0.7
- 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.
Param | Type | Description |
---|---|---|
tableName | string | The name of the table to describe |
options | object | Optional options argument |
Example
describeTable('clinic_visits')
findValue
findValue(filter) ⇒ Operation
Fetch a uuid key given a condition
Param | Type | Description |
---|---|---|
filter | object | A 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
Param | Type | Description |
---|---|---|
table | string | The target table |
record | object | Payload data for the record as a JS object |
options | object | Optional 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
Param | Type | Description |
---|---|---|
table | string | The target table |
records | function | A function that takes state and returns an array of records |
options | object | Optional 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.
Param | Type | Description |
---|---|---|
tableName | string | The name of the table to create |
columns | array | An array of form columns |
options | object | Optional 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.
Param | Type | Description |
---|---|---|
tableName | string | The name of the table to alter |
columns | array | An array of form columns |
options | object | Optional 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
Param | Type | Description |
---|---|---|
params | object | Payload data for the message |
Example
sql({ query, options })
upsert
upsert(table, uuid, record, options) ⇒ Operation
Insert or update a record using SQL MERGE
Param | Type | Description |
---|---|---|
table | string | The target table |
uuid | string | The uuid column to determine a matching/existing record |
record | object | Payload data for the record as a JS object |
options | object | Optional 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
Param | Type | Description |
---|---|---|
logical | string | a data to check existing value for. |
table | string | The target table |
uuid | string | The uuid column to determine a matching/existing record |
record | object | Payload data for the record as a JS object or function |
options | object | Optional 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
Param | Type | Description |
---|---|---|
table | string | The target table |
uuid | string | The uuid column to determine a matching/existing record |
records | function | A function that takes state and returns an array of records |
options | object | Optional options argument |
Example
upsertMany(
'users', 'email', records, { logValues: false }
)
upsertMany(
'users', ['email', 'phone'], records, { logValues: false }
)