UNPKG

@timescaledb/typeorm

Version:

This is the official TimescaleDB plugin for TypeORM.

46 lines 1.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getCompressionStats = getCompressionStats; const core_1 = require("@timescaledb/core"); const Hypertable_1 = require("../decorators/Hypertable"); const debug_1 = require("../debug"); const debug = (0, debug_1.debugTypeOrm)('getCompressionStats'); async function getCompressionStats() { try { const target = this.target; debug(`Getting compression stats for ${target.name}`); const options = Reflect.getMetadata(Hypertable_1.HYPERTABLE_METADATA_KEY, target); if (!options) { const error = 'Entity is not a hypertable'; debug(error); throw new Error(error); } const hypertable = core_1.TimescaleDB.createHypertable(this.metadata.tableName, options); const sql = hypertable .compression() .stats({ select: { total_chunks: true, compressed_chunks: true, }, }) .build(); const [stats] = await this.query(sql); const result = { compressed_chunks: stats?.compressed_chunks ?? 0, total_chunks: stats?.total_chunks ?? 0, }; debug('Compression stats retrieved'); return result; } catch (error) { const e = error; const errorStr = 'Error getting compression stats' + (e.message ? `: ${e.message}` : ''); debug(errorStr); return { compressed_chunks: 0, total_chunks: 0, }; } } //# sourceMappingURL=get-compression-stats.js.map