Workflow
The relatix workflow mirrors the journey of a relational schema—from defining the tables to putting them to use. You first lay out the structure (tables and references), then enrich it with consistent data, and finally retrieve typed utilities to read or modify that data. Each step is chained to the previous one, making the progression linear and easy to follow.
- Initial table definition: Use the
Tablesfunction with an optional configuration object to generate the table constructor. - Adding tables: Chain the constructor with
.addTablesto create an initial set of tables. - Adding additional tables: The
.addTablesmethod can be chained as many times as necessary to include tables that contain references to tables defined by previous calls. - Populating data: Add entries to the tables with
.populate. - Finalisation: Call
.done()to obtain a set of utilities for interacting with the model.
javascript
import { Tables } from "relatix";
export const model = Tables(
// Tables configuration parameters
)
.addTables({
// Adding standalone tables (internal references allowed)
})
.addTables((Ref) => {
// Adding tables that reference the existing ones
})
.populate(({ Table1, Table2, ... }) => ({
// Filling the tables with concrete data
}))
.done();Example:
typescript
import { Tables, SelfRef, Text, Number } from "relatix";
const model = Tables()
.addTables({
People: {
name: Text,
age: Number,
favouriteCoWorker: SelfRef as typeof SelfRef | null,
},
Projects: { title: Text, description: Text },
})
.addTables((Ref) => ({
Tasks: { title: Text, assignedTo: Ref("People"), project: Ref("Projects") },
}))
.populate(({ People, Projects }) => ({
People: {
alice: { name: "Alice", age: 25, favouriteCoWorker: People("bob") },
bob: { name: "Bob", age: 30, favouriteCoWorker: null },
james: { name: "James", age: 26, favouriteCoWorker: People("alice") },
},
Projects: {
proj1: { title: "Website Redesign", description: "Revamp company site" },
},
Tasks: {
task1: {
title: "Design Homepage",
assignedTo: People("alice"),
project: Projects("proj1"),
},
},
}))
.done();
export { tables, initIds, create, select, commit, deepSelect } = model;The utilities produced are:
tables: the defined tablesinitIds: mapping between the keys used inpopulate(initial state) and their idscreate: contains an entry creator for each tableselect: memoised selectors for entriescommit: enables create‑update‑delete operations on the modeldeepSelect: selectors that resolve references within entries
Each of these elements is detailed in the following sections.
