本文整理汇总了TypeScript中mssql.connect函数的典型用法代码示例。如果您正苦于以下问题:TypeScript connect函数的具体用法?TypeScript connect怎么用?TypeScript connect使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了connect函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: async
searchPosSales: async (conditions, context) => {
let sqlString = `
SELECT id, payment_no, seat_code, performance_day
FROM pos_sales
WHERE 1 = 1`;
if (conditions.from != null) {
sqlString += ` AND performance_day >= '${conditions.from}'`;
}
if (conditions.to != null) {
sqlString += ` AND performance_day <= '${conditions.to}'`;
}
sql.close();
return await sql.connect(configs.mssql).then(async connection => {
return await connection.request().query(sqlString).then(docs => {
connection.close();
return docs.recordset.map(doc => {
return { $and: [
{ payment_no: doc.payment_no },
{ seat_code: doc.seat_code },
{ performance_day: moment(doc.performance_day).format('YYYYMMDD') }]}
});
});
});
},
示例2: query
query(callback:(err, rows: Array<IRow>) => void) {
var connectionString = `mssql://${this.config.user}:${this.config.password}@${this.config.host}/${this.config.database}`;
var sql = `SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_CATALOG = '${this.config.database}'`;
mssql.connect(connectionString)
.then(() => new mssql.Request().query(sql)
.then((recordSet: Array<IRowDataPacket>) => callback(null, recordSet.map(row => {
return {
tableName: row.TABLE_NAME,
name: row.COLUMN_NAME,
defaultValue: row.COLUMN_DEFAULT,
isNullable: row.IS_NULLABLE === "YES",
type: row.DATA_TYPE
};
})))
.catch(err => callback(err, null)))
.catch(err => callback(err, null));
}
示例3:
/** Samples from https://github.com/patriksimek/node-mssql#promises */
import * as sql from "mssql";
const config = {
user: '...',
password: '...',
server: 'localhost', // You can use 'localhost\\instance' to connect to named instance
database: '...',
options: {
encrypt: true // Use this if you're on Windows Azure
}
};
const value = 50;
sql.connect(config).then(function() {
sql.query`select * from mytable where id = ${value}`.then(function(recordset) {
console.dir(recordset);
}).catch(function(err) {
// ... error checks
});
}).catch(function(err) {
// ... error checks
});
示例4:
/** Samples from https://github.com/patriksimek/node-mssql#promises */
import * as sql from "mssql";
const config = {
user: '...',
password: '...',
server: 'localhost', // You can use 'localhost\\instance' to connect to named instance
database: '...',
options: {
encrypt: true // Use this if you're on Windows Azure
}
};
sql.connect(config)
.then(function() {
const value = 50;
// Query
new sql.Request()
.input('input_parameter', sql.Int, value)
.query('select * from mytable where id = @input_parameter').then(function(recordset) {
console.dir(recordset);
}).catch(function(err) {
// ... error checks
});
// Stored Procedure
示例5: function
encrypt: true // Use this if you're on Windows Azure
}
};
sql.connect(config, function(err) {
// ... error checks
var request = new sql.Request();
request.stream = true; // You can set streaming differently for each request
request.query('select * from verylargetable'); // or request.execute(procedure);
request.on('recordset', function(columns) {
// Emitted once for each recordset in a query
});
request.on('row', function(row) {
// Emitted for each row in a recordset
});
request.on('error', function(err) {
// May be emitted multiple times
});
request.on('done', function(affected) {
// Always emitted as the last one
});
});
sql.on('error', function(err) {
// ... error handler
});
示例6: function
}
};
const value = 50;
sql.connect(config, function(err) {
// ... error checks
// Query
new sql.Request().query('select 1 as number', function(err, recordset) {
// ... error checks
console.dir(recordset);
});
// Stored Procedure
new sql.Request()
.input('input_parameter', sql.Int, value)
.output('output_parameter', sql.VarChar(50))
.execute('procedure_name', function(err, recordsets, returnValue) {
// ... error checks
console.dir(recordsets);
});
});
sql.on('error', function(err) {
// ... error handler
});
示例7:
.catch((ex) => {
res.status(500).end();
})
})
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'public', 'index.html'));
})
var config: sql.config = {
server: process.env.DB_HOST,
database: process.env.DB_NAME,
user: process.env.DB_USERNAME,
password: process.env.DB_PASSWORD,
options: {
encrypt: true // Use this if you're on Windows Azure
}
};
sql.connect(config).then(() => {
app.listen(app.get('port'), () => {
console.log(`Tweeter Center Tweet Analyzer Started Up`)
});
})
.catch((ex) => {
console.log('Could not connect to sql database');
console.log(JSON.stringify(ex));
})