nope.db
Version:
A modern, simple, and async JSON database for Node.js with zero dependencies and a data-safe queue.
93 lines (92 loc) • 3.23 kB
TypeScript
import { ClearOptions } from "./utils.js";
export interface NopeDbSettings {
path?: string;
spaces?: number;
separator?: string;
}
export declare class NopeDB {
private settings;
private storage;
/**
* Creates a new database instance or loads an existing one.
* @param {NopeDbSettings} [settings] Database settings.
* @throws {DatabaseError} Throws an error if the provided settings are invalid.
*/
constructor(settings?: NopeDbSettings);
/**
* Adds a value to an element in the database.
* @returns {Promise<number>} The total result.
*/
add(id: string, value: number): Promise<number>;
/**
* Returns all data in the database.
* @returns {Promise<object>} All data.
*/
all(): Promise<object>;
/**
* Clears all data in the database.
* Requires a confirmation object to prevent accidental deletion.
* @param {ClearOptions} options Must be { confirm: true }
* @returns {Promise<true>}
*/
clear(options: ClearOptions): Promise<true>;
/**
* Deletes an element from the database.
* @returns {Promise<boolean>} Indicates if the deletion was successful.
*/
delete(id: string): Promise<boolean>;
/**
* Gets an element from the database.
* @returns {Promise<any>} The requested data.
*/
get(id: string): Promise<any>;
/**
* Checks if data exists in the database.
* @returns {Promise<boolean>} Indicates the presence of the data.
*/
has(id: string): Promise<boolean>;
/**
* Pushes an element into an array in the database.
* @returns {Promise<any[]>} The updated array.
*/
push(id: string, value: any): Promise<any[]>;
/**
* Sets or updates an element in the database.
* @returns {Promise<any>} The value that was set.
*/
set(id: string, value: any): Promise<any>;
/**
* Subtracts a value from an element in the database.
* @returns {Promise<number>} The remaining result.
*/
subtract(id: string, value: number): Promise<number>;
/**
* Creates a backup of the current database to a new file.
* @param {string} filePath The full path for the backup file (e.g., './my-backup.json').
* @returns {Promise<true>}
*/
backup(filePath: string): Promise<true>;
/**
* Loads data from a backup file, overwriting the current database.
* @param {string} filePath The full path of the backup file to load.
* @returns {Promise<true>}
*/
loadBackup(filePath: string): Promise<true>;
/**
* Gets an element from the database (alias for get).
* @returns {Promise<any>} The requested data.
*/
fetch(id: string): Promise<any>;
/**
* Deletes an element from the database (alias for delete).
* @returns {Promise<boolean>} Indicates if the deletion was successful.
*/
remove(id: string): Promise<boolean>;
/**
* Clears all data in the database (alias for clear).
* Requires a confirmation object to prevent accidental deletion.
* @param {ClearOptions} options Must be { confirm: true }
* @returns {Promise<true>}
*/
reset(options: ClearOptions): Promise<true>;
}