本文整理汇总了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(''));