本文整理汇总了TypeScript中mssql.ConnectionPool.connect方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ConnectionPool.connect方法的具体用法?TypeScript ConnectionPool.connect怎么用?TypeScript ConnectionPool.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mssql.ConnectionPool
的用法示例。
在下文中一共展示了ConnectionPool.connect方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: test_promise_returns
function test_promise_returns() {
// Methods return a promises if the callback is omitted.
var connection: sql.ConnectionPool = new sql.ConnectionPool(config);
connection.connect().then(() => { });
connection.close().then(() => { });
var preparedStatment = new sql.PreparedStatement(connection);
preparedStatment.prepare("SELECT @myValue").then(() => { });
preparedStatment.execute({ myValue: 1 }).then((recordSet) => { });
preparedStatment.unprepare().then(() => { });
var transaction = new sql.Transaction(connection);
transaction.begin().then(() => { });
transaction.commit().then(() => { });
transaction.rollback().then(() => { });
var request = new sql.Request();
request.batch('create procedure #temporary as select * from table').then((recordset) => { });
request.batch<Entity>('create procedure #temporary as select * from table;select 1 as value').then((recordset) => { });
request.bulk(new sql.Table("table_name")).then(() => { });
request.query('SELECT 1').then((recordset) => { });
request.query`SELECT ${1} as value`.then(res => { });
request.query<Entity>('SELECT 1 as value').then(res => { });
request.execute('procedure_name').then((recordset) => { });
}
示例2: async
mergeFunc: async (context) => {
let mergeSuccess = false;
const currentTime = moment().format("YYYY-MM-DD HH:mm:ss");
const commonCols = [
'store_code', 'pos_no', 'receipt_no', 'no1', 'no2', 'type', 'payment_no', 'performance_id', 'seat_code',
'performance_type', 'performance_day', 'start_time', 'sales_date', 'section_code', 'plu_code', 'item_name',
'sales_amount', 'unit_price', 'unit', 'sum_amount', 'payment_type', 'cash', 'payment_type1', 'payment_type2',
'payment_type3', 'payment_type4', 'payment_type5', 'payment_type6', 'payment_type7', 'payment_type8',
'customer1', 'customer2', 'entry_flg', 'entry_date'
];
let mergeCols: string[] = [];
commonCols.forEach(col => mergeCols.push(`${col} = src.${col}`));
const server = new sql.ConnectionPool(configs.mssql);
await server.connect().then(async pool => {
await new sql.Request(pool).query(`
INSERT pos_sales (${[...commonCols, ...['created_at']].join(',')})
SELECT ${[...commonCols, ...[`'${currentTime}'`]].join(',')}
FROM pos_sales_tmp
WHERE NOT EXISTS (
SELECT * FROM pos_sales ps
WHERE IsNull(ps.payment_no, '') = IsNull(pos_sales_tmp.payment_no, '')
AND IsNull(ps.seat_code, '') = IsNull(pos_sales_tmp.seat_code, '')
AND IsNull(ps.performance_day, '') = IsNull(pos_sales_tmp.performance_day, '')
AND IsNull(ps.receipt_no, '') = IsNull(pos_sales_tmp.receipt_no, '')
AND IsNull(ps.no1, '') = IsNull(pos_sales_tmp.no1, '')
) AND pos_sales_tmp.uuid = '${context.funcId}';`);
await new sql.Request(pool).query(`
UPDATE tgt
SET ${[...mergeCols, ...[`updated_at = '${currentTime}'`]].join(',')}
FROM dbo.pos_sales AS tgt
INNER JOIN pos_sales_tmp AS src ON (
src.uuid = '${context.funcId}'
AND IsNull(tgt.payment_no, '') = IsNull(src.payment_no, '')
AND IsNull(tgt.seat_code, '') = IsNull(src.seat_code, '')
AND IsNull(tgt.performance_day, '') = IsNull(src.performance_day, '')
AND IsNull(tgt.receipt_no, '') = IsNull(src.receipt_no, '')
AND IsNull(tgt.no1, '') = IsNull(src.no1, '')
);`);
await new sql.Request(pool).query(`DELETE FROM pos_sales_tmp WHERE uuid = '${context.funcId}';`);
}).then(async result => {
mergeSuccess = true;
context.log(`${context.bindingData.name}ファイル: マージしました。`);
await posSalesRepository.processComplete(context);
}).catch(err => {
mergeSuccess = false;
context.log(`${context.bindingData.name}ファイル: マージ分はエラーが出ています。`);
Logs.writeErrorLog(context, `${context.bindingData.name}ファイル` + "\n" + err.stack);
});
server.close();
return mergeSuccess;
},