當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。