Curiosity

SQL / SQLite recipe

Source: SqlSample/ · SQLite (seeded on first run from seed.sql), but the same code drops onto PostgreSQL or MySQL with a one-line driver change.

Owns in the academic graph: universities, countries, departments, programs, faculty, research areas.

What it teaches

  • Relational join → graph mapping by issuing multiple SELECTs and stitching them in code.
  • Composite keys constructed from multiple columns (<University>/<Department>).
  • Node.FromKey(...) to refer to a node whose key is built elsewhere in the run.
  • Self-seeding SQLite so the recipe runs end-to-end without manual setup.

Composite keys + Node.FromKey

var deptIdToKey = new Dictionary<int, string>();
foreach (var d in departments)
{
    var key = $"{d.University}/{d.Name}";
    deptIdToKey[d.Id] = key;

    var department = graph.AddOrUpdate(new Nodes.Department
    {
        Id   = key,
        Name = d.Name,
    });

    // Reference the University by its key — emitted earlier in this run.
    graph.Link(department,
               Node.FromKey(nameof(Nodes.University), d.University),
               Edges.PartOf, Edges.HasDepartment);
}

// Programs reference Departments via the in-memory ID lookup.
foreach (var p in programs)
{
    if (!deptIdToKey.TryGetValue(p.DepartmentId, out var deptKey)) continue;
    var programKey = $"{deptKey}/{p.Name}";
    var program = graph.AddOrUpdate(new Nodes.Program { Id = programKey });
    graph.Link(Node.FromKey(nameof(Nodes.Department), deptKey), program,
               Edges.OffersProgram, Edges.ProgramOf);
}

Configuration

Variable Default
RECIPE_DB_PATH data/universities.db
RECIPE_SEED_SQL data/seed.sql
CURIOSITY_CONNECTOR_NAME SQL Sample (Universities)

Reuse notes

  • Swap SqliteSource.cs for the PostgreSQL/MySQL recipe's source file when you graduate to a production database.
  • Use composite keys when the same name can appear under different parents (departments under universities).
  • Load entire tables into memory when they're small; for large tables, switch to the PostgreSQL / MySQL recipe which uses keyset pagination.