当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript sprintf.sprintf函数代码示例

本文整理汇总了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);
			}
		});
});
开发者ID:ketsugi,项目名称:pipeline.sg,代码行数:35,代码来源:index.ts

示例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);
}
开发者ID:ketsugi,项目名称:pipeline.sg,代码行数:11,代码来源:database.ts

示例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);
});
开发者ID:ketsugi,项目名称:pipeline.sg,代码行数:12,代码来源:app.ts

示例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':
开发者ID:ketsugi,项目名称:pipeline.sg,代码行数:31,代码来源:database.ts


注:本文中的sprintf.sprintf函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。