本文整理匯總了TypeScript中sqlcmd-pg.Connection.on方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Connection.on方法的具體用法?TypeScript Connection.on怎麽用?TypeScript Connection.on使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sqlcmd-pg.Connection
的用法示例。
在下文中一共展示了Connection.on方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: Connection
interface Statistic {
package_id?: number
day: Date
downloads: number
}
export const db = new Connection({
host: '127.0.0.1',
port: 5432,
database: 'npm-history',
})
// connect db log events to local logger
db.on('log', ev => {
const args = [ev.format].concat(ev.args)
logger[ev.level].apply(logger, args)
})
const NPM_EPOCH = new Date('2009-09-29')
/**
Custom-built 'INSERT INTO <table> (<columns>) VALUES (<row1>), (<row2>), ...;'
SQL query for inserting statistic rows. I don't think there are any limits on
the number of parameters you can have in a prepared query.
*/
function buildMultirowInsert(package_id: number, statistics: Statistic[]): [string, any[]] {
const args: any[] = [package_id]
const tuples: string[] = statistics.map(statistic => {
const day_string = moment.utc(statistic.day).format('YYYY-MM-DD')
const tuple = [
'$1',