@timescaledb/core
Version:
The `@timescaledb/core` package provides fundamental building blocks for working with TimescaleDB in TypeScript/JavaScript applications. It includes SQL query builders and utilities for managing hypertables, continuous aggregates, compression, and other T
48 lines • 1.76 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CompressionBuilder = void 0;
const schemas_1 = require("@timescaledb/schemas");
const utils_1 = require("@timescaledb/utils");
const debug_1 = require("./debug");
const debug = (0, debug_1.debugCore)('Compression');
class CompressionStatsBuilder {
constructor(name, select) {
this.statements = [];
this.name = name;
this.options = select;
}
build() {
debug(`Building compression stats query for '${this.name}'`);
this.statements.push(`SELECT`);
const columns = [];
if (this.options.total_chunks) {
columns.push(`COALESCE(total_chunks, 0)::integer as total_chunks`);
}
if (this.options.compressed_chunks) {
columns.push(`COALESCE(number_compressed_chunks, 0)::integer as compressed_chunks`);
}
if (columns.length === 0) {
this.statements.push(`*`);
}
else {
this.statements.push(columns.join(',\n'));
}
const literalName = (0, utils_1.escapeLiteral)(this.name);
this.statements.push(`FROM hypertable_compression_stats(${literalName});`);
const result = this.statements.join('\n');
debug(`Compression stats query built for '${this.name}':\n${result}`);
return result;
}
}
class CompressionBuilder {
constructor(name, options) {
this.name = name;
this.options = options;
}
stats(statOpts) {
const select = schemas_1.CompressionSelectSchema.parse(statOpts.select);
return new CompressionStatsBuilder(this.name, select);
}
}
exports.CompressionBuilder = CompressionBuilder;
//# sourceMappingURL=compression.js.map