本文整理汇总了TypeScript中sprintf.sprintf函数的典型用法代码示例。如果您正苦于以下问题:TypeScript sprintf函数的具体用法?TypeScript sprintf怎么用?TypeScript sprintf使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sprintf函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
router.get('/company/:name', function(req: any, res: any): void {
console.log(sprintf('Getting information on company %s', req.params.name));
let company: Pipeline.Company;
let availablePetrol: Pipeline.Petrol[] = [];
db.query('\
SELECT c.id, c.name AS companyName, p.name AS petrolName, t.name AS type, r.price, r.last_updated AS lastUpdated\
FROM companies AS c, petrol AS p, petroltypes AS t,\
(SELECT petrol_id, price, last_updated\
FROM petrolprices\
WHERE id IN\
(SELECT MAX(id)\
FROM petrolprices\
GROUP BY petrol_id)\
ORDER BY petrol_id ASC) AS r\
WHERE c.name = LOWER(?)\
AND c.id = p.company_id\
AND p.type = t.id\
AND p.id = r.petrol_id\
', [req.params.name], function(err: any, rows: any, fields: any) {
if (err) {
db.handleMySQLError(res, err);
} else if (rows.length > 0) {
rows.forEach((row: any) => {
let petrol = new Pipeline.Petrol(row.petrolName, row.type, row.price, row.lastUpdated);
availablePetrol.push(petrol);
});
company = new Pipeline.Company(rows[0].id, rows[0].companyName, availablePetrol);
res.status(200).send(company);
} else {
res.status(404);
}
});
});
示例2: function
databaseConnection.handleMySQLError = function(res: any, err: any) {
var error = sprintf('Error %d: %s', err.errno, err.code)
console.error(error);
var status = 500;
switch (err.code) {
case 'ER_NO_REFERENCED_ROW_2':
status = 404;
break;
}
res.status(status).send(error);
}
示例3: function
app.all('*', function (req: any, res: any, next: any) {
console.log(sprintf('%s called on endpoint %s with query: %s', req.method, req.path, JSON.stringify(req.query)));
passport.authenticate('localapikey', function(err: any, user: any, info: any) {
if (err) {
return next(err);
} else if (!user) {
} else {
req.user = user;
}
return next();
})(req, res, next);
});
示例4: require
// Load configuration file
var config = require('./config.json');
// Load modules
var sprintf = require('sprintf').sprintf;
var mysql = require('mysql');
// Initialise database connection
var databaseConnection = mysql.createConnection({
host: config.mysql.host,
port: config.mysql.port,
user: config.mysql.user,
password: config.mysql.password,
database: config.mysql.schema
});
console.log(sprintf("Connecting to database at %s:%d...", config.mysql.host, config.mysql.port));
databaseConnection.connect(function(err: any) {
if (err) {
console.error('Error connecting: %s', err.stack);
return;
}
console.log('Connected as id: %d', databaseConnection.threadId);
});
databaseConnection.handleMySQLError = function(res: any, err: any) {
var error = sprintf('Error %d: %s', err.errno, err.code)
console.error(error);
var status = 500;
switch (err.code) {
case 'ER_NO_REFERENCED_ROW_2':