@clickup/pg-microsharding
Version:
Microshards support for PostgreSQL
36 lines • 1.58 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.weights = weights;
const compact_1 = __importDefault(require("lodash/compact"));
const partition_1 = __importDefault(require("lodash/partition"));
const getSchemaWeights_1 = require("../internal/getSchemaWeights");
const listActiveSchemas_1 = require("../internal/listActiveSchemas");
const names_1 = require("../internal/names");
const normalizeCellNumbers_1 = require("../internal/normalizeCellNumbers");
/**
* Similar to listActiveSchemas(), but also returns the weight of each
* microshard and its number.
*/
async function weights({ dsn, weightSql, verbose, }) {
const schemas = await (0, listActiveSchemas_1.listActiveSchemas)({ dsn });
const weights = await (0, getSchemaWeights_1.getSchemaWeights)({ dsn, schemas, weightSql, verbose });
const res = (0, compact_1.default)([...weights.entries()].map(([schema, shard]) => {
const no = (0, names_1.shardNo)(schema);
return no !== null
? {
...shard,
otherNormalized: { ...shard.other },
schema,
no,
}
: null;
}));
for (const group of (0, partition_1.default)(res, ({ no }) => no === 0)) {
(0, normalizeCellNumbers_1.normalizeCellNumbers)(group.map(({ otherNormalized }) => otherNormalized));
}
return res;
}
//# sourceMappingURL=weights.js.map