tona-db-mini
Version:
Tona-DB mini is a JavaScript library for simulating small local databases in JSON.
54 lines (53 loc) • 1.75 kB
TypeScript
import { Config } from "../config/schema";
import { Filter, NonArrayObject } from "./types";
/**
* Represents a local collection backed by a JSON file.
*/
export declare class Collection<T extends NonArrayObject> {
private filePath;
private config;
/**
* @param collectionName Name of the collection (used as file name)
* @param config The configuration options
*/
constructor(collectionName: string, config?: NonNullable<Required<Config>>);
/**
* Reads and parses the JSON data
* @returns {T[]} The parsed data
*/
private read;
/**
* Serializes and writes data to the file
* @param data The data to write
*/
private write;
/**
* Checks if an item matches the provided filter.
* @param item The item to check
* @param filter The filter to apply
* @returns {boolean} Whether the item matches the filter
*/
private matchesFilter;
/**
* Returns items matching the provided filter.
* @param filter The filter to apply (object or predicate function)
* @returns {T[]} The filtered items
*/
get(filter?: Filter<T>): T[];
/**
* Adds one or more items to the collection.
* @param data A single item or array of items to add
*/
add(data: T | T[]): void;
/**
* Deletes items matching the provided filter.
* @param filter The filter to apply (object or predicate function)
*/
del(filter?: Filter<T>): void;
/**
* Updates items matching the provided filter.
* @param filter The filter to apply (object or predicate function)
* @param data The partial data to update on each matching item
*/
update(filter: Filter<T>, data: Partial<T>): void;
}