Skip to content

Getting started

The TypeScript SDK, for web apps, Node and agents written in TypeScript:

Terminal window
npm install @nocentraldb/sdk

The Rust SDK:

Terminal window
cargo add nocentraldb

The command-line tool ncdb builds model.lock.json from your schema. How it is distributed is not decided yet.

import { nc } from "@nocentraldb/sdk";
export const model = nc.model({
tasks: nc.collection(
{
title: nc.string(),
status: nc.oneOf(["open", "in_progress", "done"]),
priority: nc.int(),
},
{
indexes: {
byStatusPriority: nc.index(["status", "priority"], { equal: 1 }),
},
},
),
});

Then build the lock that the Rust core and both SDKs read:

Terminal window
ncdb model build
const db = await nc.open({ model, lock, relay: "wss://relay.example.com" });
const project = await db.spaces.create();
await project.write((tx) => {
tx.create(model.tasks, {
title: "Write the README",
status: "open",
priority: 1,
});
});

A write is designed to resolve once the change is in the local log and the view, before the relay has it. Read on in Concepts.