Complete API documentation for all NebulaDB components and methods.
createDb(options)Creates a new database instance.
Parameters:
options: DbOptions — Configuration optionsadapter: Adapter — Storage adapter to useplugins?: Plugin[] — Optional array of pluginsReturns: IDatabase
import { createDb } from '@nebula-db/core';
import { MemoryAdapter } from '@nebula-db/adapter-memory';
const db = createDb({ adapter: new MemoryAdapter() });
IDatabaseProperties:
collections: Map<string, ICollection>adapter: Adapterplugins: Plugin[]Methods:
collection(name: string, options?: CollectionOptions): ICollection — Get or create a collectionsave(): Promise<void> — Save database stateICollectionMethods:
insert(doc): Promise<Document> — Insert a documentfind(query?): Promise<Document[]> — Find matching documentsfindOne(query): Promise<Document | null> — Find single documentupdate(query, update): Promise<number> — Update matching documentsdelete(query): Promise<number> — Delete matching documentssubscribe(query, callback): () => void — Subscribe to changes| Operator | Description |
|---|---|
$eq | Equal to |
$ne | Not equal to |
$gt | Greater than |
$gte | Greater than or equal |
$lt | Less than |
$lte | Less than or equal |
$in | In array |
$nin | Not in array |
$regex | Regular expression |
$exists | Field 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'] } });
| Operator | Description |
|---|---|
$and | Logical AND |
$or | Logical OR |
$not | Logical NOT |
// AND
await collection.find({ $and: [{ age: { $gt: 25 } }, { status: 'active' }] });
// OR
await collection.find({ $or: [{ status: 'active' }, { age: { $gt: 30 } }] });
| Operator | Description |
|---|---|
$set | Set field values |
$unset | Remove fields |
$inc | Increment numeric fields |
$push | Add items to arrays |
$pull | Remove 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' } });
Documenttype Document = { id: string; [key: string]: any; };
Querytype Query = { [key: string]: any | QueryCondition; } | LogicalQuery;
DbOptionsinterface DbOptions { adapter: Adapter; plugins?: Plugin[]; }
Adapterinterface Adapter {
load(): Promise<Record<string, Document[]>>;
save(data: Record<string, Document[]>): Promise<void>;
connect?(): Promise<void>;
close?(): Promise<void>;
}