Minigraf
v2.0.4 (latest)

Corestore Tutorial — Setup

This tutorial series walks through Minigraf's Datalog query language from the ground up — basic facts and queries, bi-temporal operators (:as-of, :valid-at), recursive rules, negation, aggregates, expression clauses, prepared queries, disjunction and user-defined functions, in the backdrop of a fictional, multi-seller online marketplace. Every section builds on a shared dataset drawn from the Corestore storyline, so you see each feature in context rather than in isolation.

Meet Corestore#

Corestore is a fictional single-seller (initially) consumer electronics retailer. It stocks the usual suspects — laptops, phones, accessories — and processes a steady stream of orders from a small cast of customers. For most of the tutorial, there is one seller and one storefront. The final section, Marketplace, introduces competing sellers to motivate more complex queries necessitated by the additional multi-seller layer.

The cast#

CharacterArchetypeRole in the tutorial
AliceFrequent buyerEstablishes the basics — her orders are clean and predictable
BenPrice-watcherAnchors the bi-temporal sections; scrutinises price drops and receipt corrections
ClaraComplicated historyDrives negation, aggregates, and disjunction — split shipments, rescheduled deliveries, cancelled items

Prerequisites#

You need a working Rust toolchain. If you do not have one:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Then either install the published crate:

cargo install minigraf

Or clone and build from source:

git clone https://github.com/project-minigraf/minigraf
cd minigraf
cargo build

Load the Corestore dataset#

All tutorial sections share a common starting dataset. Load it once and persist it to a local file before working through any section:

cargo run --bin minigraf -- --file corestore.graph < demos/tutorial_corestore_setup.txt

This creates corestore.graph in the current directory and runs 3 transactions (tx_count 1–3): product catalogue, customer records, and initial orders. Every tutorial page assumes these facts are present and references them by name.

Start the REPL#

cargo run --bin minigraf -- --file corestore.graph

This opens corestore.graph (created above) and drops you into an interactive session. Type Datalog commands at the prompt. To exit, press Ctrl-D or type EXIT.

A note on transaction counts#

tx_count increments once per transact or retract call — never on queries. The tutorial sections must be run in order for :as-of N examples to produce the results shown. If you run extra transacts between sections (for example, to experiment), your tx_count will be higher than expected and the time-travel examples will not match. If that happens, the simplest fix is to delete corestore.graph and re-run the load command above.

Visualize: you can also explore this dataset without installing anything. The time travel visualizer has it as a sample, with every write from sections 1 to 3 already applied and the same transaction numbers as the text. It opens at tx 3, right after setup.

Tutorial sections#

SectionTopic
SetupThis page
1. Basic transact + queryAlice places her first order
2. :as-ofBen's price drop — time travel by transaction time
3. :valid-at and :any-valid-timePricing correction — time travel by valid time
4. Recursive rulesCategory hierarchy traversal
5. NegationClara's split shipment — not and not-join
6. Aggregates and window functionsTotals, rankings, and the :with trap
7. Expression clausesFilters, arithmetic, and string predicates
8. Prepared queriesParse once, execute many with $bind-slots
9. Disjunctionor and or-join
10. User-defined functionsCustom predicates and aggregates
11. MarketplaceMulti-seller queries

Reference#

Full syntax — value types, operators, rule syntax, temporal modifiers — is in the Datalog Reference.

How this page was assembled

This page is 9 fragments. Minigraf picked them from docs.graph with this query, where the version is a point on the valid-time axis:

(query [:find ?order ?blob ?added :valid-at "2002-01-01T00:00:04Z" :where [?f :frag/page "tutorial-setup"] [?f :frag/order ?order] [?f :frag/blob ?blob] [?f :frag/added-in ?added]])

Run it in the query console