juanluispaz / ts-sql-query

Type-safe SQL query builder like QueryDSL or JOOQ in Java or Linq in .Net for TypeScript with MariaDB, MySql, Oracle, PostgreSql, Sqlite and SqlServer support.
https://ts-sql-query.readthedocs.io/
MIT License
291 stars 19 forks source link

LoggingQueryRunner: Use performance.now() in non-Node environments #124

Closed threema-danilo closed 6 months ago

threema-danilo commented 6 months ago

Since #43, the LoggingQueryRunner calls process.hrtime.bigint() to get a timestamp for performance measurements. However, this API is not present in non-NodeJS environments (e.g. in the browser).

This PR adds a wrapper function that uses performance.now() as a fallback if the process module is not available.

Note: In theory we could migrate to using the value returned by performance.now() on all platforms. However, this would be a breaking change since some users might have subclassed the logger, because process.hrtime.bigint() returns nanoseconds as bigint, while performance.now() returns a float in milliseconds. To avoid a breaking change, I multiply the value returned from performance.now() by 1_000_000 and wrap it in a bigint, to stick to the same time base. Loss of precision might occur (but browsers may limit timing performance anyways for security reasons).

juanluispaz commented 6 months ago

This change is included in ts-sql-query 1.64.0, which is already published.