Skip to content

Approaches for incremental data loaders #1311

Answered by Fil
ltostes asked this question in Q&A
Discussion options

You must be logged in to vote

Here's an incremental data loader, which uses Framework's own cache if present and appends a line to it.

❯ cat src/incremental.csv.js
import { readFileSync } from "node:fs";

try {
  const c = readFileSync("src/.observablehq/cache/incremental.csv", "utf-8");
  process.stdout.write(c);
} catch (err) {
  process.stdout.write("a\n");
}
process.stdout.write(`${Math.random()}\n`);

Of course you an do something more interesting when you read it—here I'm just piping it straight back to framework with the additional line.

To run it again and generate a newer version, I only need to run touch src/incremental.csv.js.

(Note that I'm using the new source root location src—you might need to replace t…

Replies: 1 comment 1 reply

Comment options

Fil
May 7, 2024
Collaborator

You must be logged in to vote
1 reply
@ltostes
Comment options

Answer selected by ltostes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants