Skip to content

Getting started

Quick start

Build your first graph database in 5 minutes

This guide builds a small social graph of users who follow each other. It covers defining a schema, writing nodes and edges, querying them, and closing the database.

1. Define your schema

A schema lists the node and edge types and their properties. This one has a user node type and a follows edge type.

social.ts
import { kite } from '@kitedb/core';// Define schema inline when opening the databaseconst db = await kite('./social.kitedb', {  nodes: [    {      name: 'user',      props: {        name: { type: 'string' },        email: { type: 'string' },      },    },  ],  edges: [    {      name: 'follows',      props: {        followedAt: { type: 'int' },  // Unix timestamp      },    },  ],});

2. Add some data

TypeScript
// Create usersconst alice = db.insert('user')  .values('alice', { name: 'Alice Chen', email: 'alice@example.com' })  .returning();const bob = db.insert('user')  .values('bob', { name: 'Bob Smith', email: 'bob@example.com' })  .returning();// Create a follow relationshipdb.link(alice.id, 'follows', bob.id, {  followedAt: Math.floor(Date.now() / 1000),});

3. Query the graph

TypeScript
// Find all users Alice followsconst following = db  .from(alice.id)  .out('follows')  .nodes();console.log('Alice follows:', following.length, 'users');// Check if Alice follows Bobconst followsBob = db.hasEdge(alice.id, 'follows', bob.id);console.log('Alice follows Bob:', followsBob);

4. Close the database

TypeScript
// Always close when donedb.close();

Next steps

Each of these guides goes deeper on one step from this page: