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