API Reference

Complete API documentation for all NebulaDB components and methods.

Core API

createDb(options)

Creates a new database instance.

Parameters:

Returns: IDatabase

import { createDb } from '@nebula-db/core';
import { MemoryAdapter } from '@nebula-db/adapter-memory';

const db = createDb({ adapter: new MemoryAdapter() });

IDatabase

Properties:

Methods:

ICollection

Methods:

Query Operators

Comparison

OperatorDescription
$eqEqual to
$neNot equal to
$gtGreater than
$gteGreater than or equal
$ltLess than
$lteLess than or equal
$inIn array
$ninNot in array
$regexRegular expression
$existsField exists
// Equal to (shorthand)
await collection.find({ age: 30 });

// Greater than
await collection.find({ age: { $gt: 25 } });

// In array
await collection.find({ status: { $in: ['active', 'pending'] } });

Logical

OperatorDescription
$andLogical AND
$orLogical OR
$notLogical NOT
// AND
await collection.find({ $and: [{ age: { $gt: 25 } }, { status: 'active' }] });

// OR
await collection.find({ $or: [{ status: 'active' }, { age: { $gt: 30 } }] });

Update Operators

OperatorDescription
$setSet field values
$unsetRemove fields
$incIncrement numeric fields
$pushAdd items to arrays
$pullRemove items from arrays
// Set fields
await collection.update({ id: '1' }, { $set: { name: 'New Name', age: 31 } });

// Increment
await collection.update({ id: '1' }, { $inc: { age: 1, count: 5 } });

// Push to array
await collection.update({ id: '1' }, { $push: { tags: 'new-tag' } });

Types

Document

type Document = { id: string; [key: string]: any; };

Query

type Query = { [key: string]: any | QueryCondition; } | LogicalQuery;

DbOptions

interface DbOptions { adapter: Adapter; plugins?: Plugin[]; }

Adapter

interface Adapter {
  load(): Promise<Record<string, Document[]>>;
  save(data: Record<string, Document[]>): Promise<void>;
  connect?(): Promise<void>;
  close?(): Promise<void>;
}