This guide writes three facts to an in-memory Triplex database, joins them with Datalog, and prints the result. It is the shortest complete path to a running program.
::: warning Pre-1.0 packages
The @triplex-build packages are available from npm and require effect@4.0.0-rc.112.
Effect 3 is incompatible. Do not use the superseded @bjacobso package names for new work.
:::
- Git
- Node.js 22 or newer
- Corepack and pnpm 10.11.0 (the repository declares the exact package-manager version)
For an application, install the published core package and its Effect peer dependency:
npm install @triplex-build/triplex effect@4.0.0-rc.112Clone the repository and install its locked dependencies:
git clone https://github.com/bjacobso/triplex.git
cd triplex
corepack enable
pnpm install --frozen-lockfileRun the checked quickstart directly from the checkout:
pnpm exec tsx --tsconfig docs/snippets/tsconfig.json docs/snippets/getting-started.tsThe complete program is:
<<< @/snippets/getting-started.ts{ts}
It prints:
{
"relationships": [
{
"person": "Alice",
"company": "Acme"
}
]
}The repository's smaller demo is another executable starting point:
pnpm exec tsx --tsconfig docs/snippets/tsconfig.json examples/demo/demo.tsYou only need four Effect ideas for this example:
Triplesis a service tag.yield* Triplesasks the current Effect context for the database.Effect.genlets the program sequence database effects with generator syntax.KvTriples.layerconstructs the in-memory implementation of that service.Effect.providesupplies the layer, andEffect.runPromiseruns the fully provided program.
Create and share a layer at your application boundary. Do not construct a new layer inside each
request: each KvTriples.layer runtime owns a fresh in-memory database, and its contents disappear
when that runtime/process ends.
The transaction records three typed values atomically. ref(acme) is a relationship because its
value is another EntityId; the Datalog query follows that relationship by using the same
?company variable in two clauses. query returns one bounded page, which is enough for this
one-row example. Follow nextCursor for larger results or use queryAll only for trusted batch
work that intentionally needs the complete result set.
SQLite is the supported local persistent backend. Install it alongside core and Effect:
npm install @triplex-build/triplex-sqliteReplace the in-memory layer with a file-backed layer:
import { SqliteTriples } from "@triplex-build/triplex-sqlite";
const DatabaseLive = SqliteTriples.layer({ filename: "./triplex.db" });
const relationships = await Effect.runPromise(program.pipe(Effect.provide(DatabaseLive)));This is a focused replacement fragment: program is the complete program above. The convenience
layer opens the SQLite file and applies Triplex's current migration. Create it once and share it for
the application lifetime. Production hosts that separate schema migration from runtime startup
should use the explicit unmigrated composition described in Host integration.
- Experiment without installing anything in the browser Playground.
- Read Core concepts before modeling a domain with historical facts.
- Follow Configuration releases and rollback to version rules and pin operational writes to them.
- Learn query clauses and pagination in Datalog.
- Explore a database through the CLI and dashboard.
- Check the current maturity contract before choosing a production backend.