Skip to content
Logo

Changelog

for @ghostry/fabricator-census

Every release of @ghostry/fabricator-census, newest first.

v0.0.2

· Release on GitHub

New

  • @ghostry/fabricator-census/postgres builds the PostgreSQL queries a census is fed from. It never opens a connection: you run each query with your own driver.
    • sample draws a sample (Bernoulli, system, or hash).
    • count, estimate, columns, statistics, and estimatedFacts read catalog estimates and statistics.
    • aggregates computes exact whole-table facts.
    • collect runs all of it through a run(text, values) function you supply, and returns { rows, facts }.
    • coerce and parseText give 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.
  • sampleSize tells 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 })));

Docs: https://docs.ghostry.dev/fabricator/guides/census

v0.0.1

· Release on GitHub

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

Docs: https://docs.ghostry.dev/fabricator/guides/census