# Minigraf Demo Commands
# Copy and paste these commands into the REPL, or pipe them in:
#   cargo run < demos/demo_commands.txt

# ============================================================================
# BASIC DATALOG
# ============================================================================

# Add facts about Alice
(transact [[:alice :person/name "Alice"]
           [:alice :person/age 30]
           [:alice :person/city "San Francisco"]])

# Add facts about Bob
(transact [[:bob :person/name "Bob"]
           [:bob :person/age 25]
           [:bob :person/city "New York"]])

# Add facts about Carol
(transact [[:carol :person/name "Carol"]
           [:carol :person/age 28]
           [:carol :person/city "San Francisco"]])

# Create friendships (graph edges using entity references)
(transact [[:alice :friend :bob]
           [:alice :friend :carol]
           [:bob :friend :carol]])

# Query: Find all person names
(query [:find ?name
        :where [?e :person/name ?name]])

# Query: Find people and their ages
(query [:find ?name ?age
        :where [?e :person/name ?name]
               [?e :person/age ?age]])

# Query: Find people in San Francisco
(query [:find ?name
        :where [?e :person/name ?name]
               [?e :person/city "San Francisco"]])

# Query: Find Alice's friends
(query [:find ?friend-name
        :where [:alice :friend ?friend]
               [?friend :person/name ?friend-name]])

# Query: Find people older than 26
# Note: Arithmetic comparison predicates are not yet supported — see ROADMAP.md.

# Update: Alice had a birthday (retract old age, assert new age)
(retract [[:alice :person/age 30]])
(transact [[:alice :person/age 31]])

# Verify the update
(query [:find ?age
        :where [:alice :person/age ?age]])

# Add company information
(transact [[:techcorp :company/name "TechCorp"]
           [:techcorp :company/founded 2015]])

# Add employment relationships
(transact [[:alice :works-at :techcorp]
           [:bob :works-at :techcorp]])

# Query: Find who works at TechCorp
(query [:find ?name
        :where [?person :works-at :techcorp]
               [?person :person/name ?name]])

# Query: Find all facts about Alice
# Note: Wildcard entity scan requires iterating all attributes — use targeted patterns instead.

# Retract a friendship
(retract [[:alice :friend :carol]])

# Query: Find Alice's remaining friends
(query [:find ?friend-name
        :where [:alice :friend ?friend]
               [?friend :person/name ?friend-name]])

EXIT

# ============================================================================
# KEY FEATURES (v0.13.0)
# ============================================================================
#
# FACTS AND QUERIES:
# - Facts: [Entity Attribute Value] triples
# - Immutable history: facts never deleted, only retracted
# - Keyword entities: :alice, :bob (resolved to stable UUIDs)
# - Entity references: [:alice :friend :bob] creates graph relationships
# - Variable unification: ?e binds the same entity across all patterns
#
# RECURSIVE RULES (see demo_recursive.txt for full examples):
# - (rule [(reachable ?a ?b) [?a :connected ?b]])
# - (rule [(reachable ?a ?b) [?a :connected ?m] (reachable ?m ?b)])
# - Semi-naive fixed-point evaluation; handles cycles correctly
#
# STRATIFIED NEGATION (see demo_negation.txt for full examples):
# - (not [?e :banned true])              — exclude matching entities
# - (not-join [?e] [?e :dep ?d] [?d :status :bad]) — existential negation
# - Negation in rule bodies; negative cycles rejected at registration time
#
# AGGREGATION (see demo_aggregation.txt for full examples):
# - (count ?e), (count-distinct ?e)
# - (sum ?v), (sum-distinct ?v)
# - (min ?v), (max ?v)
# - :with clause for grouping: [:find ?dept (sum ?salary) :with ?e :where ...]
#
# EXPRESSION CLAUSES (see demo_expr.txt for full examples):
# - Filter predicates: [(< ?age 30)] [(>= ?x ?y)] [(= ?name "Alice")]
# - Arithmetic bindings: [(* ?price ?qty) ?total]
# - Type checks: [(string? ?v)] [(integer? ?v) ?flag]
# - String predicates: [(starts-with? ?s "pre")] [(matches? ?s "regex")]
#
# DISJUNCTION (see demo_disjunction.txt for full examples):
# - (or branch1 branch2 ...)         — union of branches (same vars per branch)
# - (or-join [?e] branch1 branch2 .) — union with branch-private variables
# - (and clause1 clause2 ...)        — group clauses into one branch
# - or / or-join usable in rule bodies
#
# BI-TEMPORAL QUERIES (see demo_bitemporal.txt for full examples):
# - (query [:find ?x :as-of 3 :where ...])              — tx-time snapshot
# - (query [:find ?x :as-of "2024-01-15T10:00:00Z" ...]) — wall-clock snapshot
# - (query [:find ?x :valid-at "2023-06-01" ...])        — valid-time query
# - (query [:find ?x :valid-at :any-valid-time ...])     — ignore valid-time filter
# - All query features (negation, aggregation, expr, disjunction) compose with both axes
#
# PERSISTENT STORAGE:
# - Single .graph file; open with OpenOptions::new().path("mydb.graph").open()
# - WAL crash safety; explicit transactions via begin_write()/commit()
# - On-disk B+tree indexes (EAVT, AEVT, AVET, VAET) with LRU page cache
#
# See ROADMAP.md for upcoming features (Phase 7.4+).
# ============================================================================
