Path: blob/master/src/packages/database/pool/util.ts
1496 views
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45// Postgres 14 is different than 13 an earlier.6// extract(epoch from timestamp) returns a "numeric", which is converted to a string by the pg driver.7// we convert this explicitly to a floating point number to get the ms since epoch.8// Note: JavaScript's new Date(...) has no hesitation converting from a float.9export function timeInSeconds(field: string, asField?: string): string {10return ` (EXTRACT(EPOCH FROM ${field})*1000)::FLOAT as ${asField ?? field} `;11}1213// Given number of seconds **in the future**.14export function expireTime(ttl_s: number = 0): Date {15return new Date(Date.now() + ttl_s * 1000);16}171819