Passer au contenu principal

mssql@4.0.3

Functions

createConnection(state)State

Creates a connection.

execute(operations)Operation

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

cleanupState(state)State

Removes unserializable keys from the state.

addRowsToRefs(state, rows)State

Sets the returned rows from a query as the first item in the state.references array, leaving state.data unchanged between operations.

flattenRows(state, rows)State

Returns a flatten object of the rows (array of arrays) with rowCount.

sql(params)Operation

Execute an SQL statement

findValue(filter)Operation

Fetch a uuid key given a condition

insert(table, record, options)Operation

Insert a record

insertMany(table, records, options)Operation

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

upsert(table, uuid, record, options)Operation

Insert or update a record using SQL MERGE

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

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

upsertMany(table, uuid, records, options)Operation

Insert or update multiple records using ON CONFLICT UPDATE and excluded

describeTable(tableName, options)Operation

List the columns of a table in a database.

insertTable(tableName, columns, options)Operation

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

modifyTable(tableName, columns, options)Operation

Alter an existing table in the database.

createConnection(state) ⇒ State

Creates a connection.

Kind: global function

ParamTypeDescription
stateStateRuntime state.

Example

createConnection(state)

execute(operations) ⇒ Operation

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

Kind: global function

ParamTypeDescription
operationsOperationsOperations to be performed.

Example

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

cleanupState(state) ⇒ State

Removes unserializable keys from the state.

Kind: global function

ParamType
stateState

Example

cleanupState(state)

addRowsToRefs(state, rows) ⇒ State

Sets the returned rows from a query as the first item in the state.references array, leaving state.data unchanged between operations.

Kind: global function

ParamTypeDescription
stateState
rowsarraythe array of rows returned from the sql query

flattenRows(state, rows) ⇒ State

Returns a flatten object of the rows (array of arrays) with rowCount.

Kind: global function

ParamTypeDescription
stateState
rowsarraythe array of rows returned from the sql query

sql(params) ⇒ Operation

Execute an SQL statement

Kind: global function
Access: public

ParamTypeDescription
paramsobjectPayload data for the message

Example

sql({ query, options })

findValue(filter) ⇒ Operation

Fetch a uuid key given a condition

Kind: global function
Access: public

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(table, record, options) ⇒ Operation

Insert a record

Kind: global function
Access: public

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(table, records, options) ⇒ Operation

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

Kind: global function
Access: public

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

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

Insert or update a record using SQL MERGE

Kind: global function
Access: public

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(logical, table, uuid, record, options) ⇒ Operation

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

Kind: global function
Access: public

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(table, uuid, records, options) ⇒ Operation

Insert or update multiple records using ON CONFLICT UPDATE and excluded

Kind: global function
Access: public

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

describeTable(tableName, options) ⇒ Operation

List the columns of a table in a database.

Kind: global function
Access: public

ParamTypeDescription
tableNamestringThe name of the table to describe
optionsobjectOptional options argument

Example

describeTable('clinic_visits')

insertTable(tableName, columns, options) ⇒ Operation

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

Kind: global function
Access: public

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(tableName, columns, options) ⇒ Operation

Alter an existing table in the database.

Kind: global function
Access: public

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