本文整理匯總了TypeScript中pg-promise.as類的典型用法代碼示例。如果您正苦於以下問題:TypeScript as類的具體用法?TypeScript as怎麽用?TypeScript as使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了as類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: createBulkAccountsSQL
public static createBulkAccountsSQL(addresses: string[]) {
if (!addresses) {
return '';
}
addresses = addresses.filter((addr) => addr);
if (addresses.length === 0) {
return '';
}
return pgp.as.format(`
INSERT into mem_accounts(address)
SELECT address from (VALUES $1:raw ) i (address)
LEFT JOIN mem_accounts m1 USING(address)
WHERE m1.address IS NULL`,
addresses.map((address) => pgp.as.format('($1)', address)).join(', '));
}
示例2: searchDelegate
public static searchDelegate(q: string, limit: number, orderBy: string, orderHow: 'ASC' | 'DESC' = 'ASC') {
if (['ASC', 'DESC'].indexOf(orderHow.toLocaleUpperCase()) === -1) {
throw new Error('Invalid ordering mechanism')
}
return pgp.as.format(`
WITH
supply AS (SELECT calcSupply((SELECT height FROM blocks ORDER BY height DESC LIMIT 1))::numeric),
delegates AS (SELECT row_number() OVER (ORDER BY vote DESC, m."publicKey" ASC)::int AS rank,
m.username,
m.address,
m.cmb,
ENCODE(m."publicKey", 'hex') AS "publicKey",
m.vote,
m."votesWeight",
m.producedblocks,
m.missedblocks,
ROUND(vote / (SELECT * FROM supply) * 100, 2)::float AS approval,
(CASE WHEN producedblocks + missedblocks = 0 THEN 0.00 ELSE
ROUND(100 - (missedblocks::numeric / (producedblocks + missedblocks) * 100), 2)
END)::float AS productivity,
COALESCE(v.voters_cnt, 0) AS voters_cnt,
t.timestamp AS register_timestamp
FROM delegates d
LEFT JOIN mem_accounts m ON d.username = m.username
LEFT JOIN trs t ON d."transactionId" = t.id
LEFT JOIN (SELECT "dependentId", COUNT(1)::int AS voters_cnt from mem_accounts2delegates GROUP BY "dependentId") v ON v."dependentId" = ENCODE(m."publicKey", 'hex')
WHERE m."isDelegate" = 1
ORDER BY \${orderBy:name} \${orderHow:raw})
SELECT * FROM delegates WHERE username LIKE \${q} LIMIT \${limit}
`, {
q: `%${q}%`,
limit,
orderBy,
orderHow
});
}
示例3:
addresses.map((address) => pgp.as.format('($1)', address)).join(', '));
示例4: pgPromise
/// <reference path='../../typescript/pg-promise' />
import * as pgPromise from 'pg-promise';
var value1 = pgPromise.as.array([]);
var value2 = pgPromise.as.array(()=>[]);
var pgp:pgPromise.IMain = pgPromise();
var value3 = pgp.as.array([]);
var value4 = pgp.as.array(()=>[]);
var value5 = pgp.as.format('hello', []);
var value6 = pgp.as.format(new pgPromise.QueryFile(''));