本文整理匯總了TypeScript中mssql.ConnectionPool類的典型用法代碼示例。如果您正苦於以下問題:TypeScript ConnectionPool類的具體用法?TypeScript ConnectionPool怎麽用?TypeScript ConnectionPool使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了ConnectionPool類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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;
},
示例3: test_classes_extend_eventemitter
function test_classes_extend_eventemitter() {
var connection: sql.ConnectionPool = new sql.ConnectionPool(config);
var transaction = new sql.Transaction();
var request = new sql.Request();
var preparedStatment = new sql.PreparedStatement();
connection.on('connect', () => { });
transaction.on('begin', () => { });
transaction.on('commit', () => { });
transaction.on('rollback', () => { });
request.on('done', () => { });
request.on('error', () => { });
preparedStatment.on('error', () => { })
}