本文整理匯總了TypeScript中sqlcmd-pg.Connection.Select方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Connection.Select方法的具體用法?TypeScript Connection.Select怎麽用?TypeScript Connection.Select使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sqlcmd-pg.Connection
的用法示例。
在下文中一共展示了Connection.Select方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: findOrCreatePackage
/**
Given a package name, return the full package row from the database, creating
one if needed.
*/
function findOrCreatePackage(name: string, callback: (error: Error, package_row?: Package) => void) {
db.Select('package')
.whereEqual({name})
.execute((error: Error, rows: Package[]) => {
if (error) return callback(error)
if (rows.length > 0) return callback(null, rows[0])
db.Insert('package')
.set({name}).returning('*')
.execute((insertError: Error, insertRows: Package[]) => {
if (insertError) return callback(insertError)
return callback(null, insertRows[0])
})
})
}
示例2: queryAverageDownloads
export function queryAverageDownloads(start: moment.Moment,
end: moment.Moment,
callback: (error: Error, packages?: {[index: string]: number}) => void) {
db.Select('package_statistic')
.add('name', 'AVG(downloads)::int AS average')
.where('downloads > -1')
.where('day >= ?', start.toDate())
.where('day < ?', end.toDate())
.groupBy('name')
.orderBy('name')
.execute((error: Error, rows: {name: string, average: number}[]) => {
if (error) return callback(error)
logger.info('averaged downloads for %d packages', rows.length)
const packages: {[index: string]: number} = {}
rows.forEach(row => packages[row.name] = row.average)
callback(null, packages)
})
}