Changelog
for @ghostry/fabricator-census
Every release of @ghostry/fabricator-census, newest first.
v0.0.2
New
@ghostry/fabricator-census/postgresbuilds the PostgreSQL queries a census is fed from. It never opens a connection: you run each query with your own driver.sampledraws a sample (Bernoulli, system, or hash).count,estimate,columns,statistics, andestimatedFactsread catalog estimates and statistics.aggregatescomputes exact whole-table facts.collectruns all of it through arun(text, values)function you supply, and returns{ rows, facts }.coerceandparseTextgive each value one type regardless of what your driver returned (int8,numeric, and so on).
census.from(rows, { facts })merges whole-table facts over the sample: exact counts and extremes win over estimates, and estimates win over the sample. A suggestion that relied on an estimate says so in its notes.sampleSizetells you how many rows a census needs.
import { collect } from "@ghostry/fabricator-census/postgres";
const { rows, facts } = await collect(
async (text, values) => (await client.query(text, values)).rows,
{ table: "users" },
);
console.log(report(census.from(rows, { facts })));
v0.0.1
Initial release.
Take a census of real data and get @ghostry/fabricator schema suggestions: how values are distributed, how often fields are missing or null, how long strings run and which characters they hold, and which strings are really enums. Suggestions come back in fabricator's own terms: Distribution variants, whereby ranges, .weighted(...) weights, and string composition.
import { census, report } from "@ghostry/fabricator-census";
console.log(report(census.from(rows)));
// $.age T.number.integer.whereby({ min: 18, max: 79, distribution: { kind: "normal", mean: 38.31, spread: 11.95 } })
// $.plan T.enum.weighted([[3528, "free"], [1237, "pro"], [235, "team"]])
Fits are scored against the exact curves fabricator draws from. A census keeps the values it observed, so treat it like the data it came from.
npm install @ghostry/fabricator-census @ghostry/fabricator
