moonlifedb
Version:
A JSON database with a bunch of tools and typescript support.
122 lines (121 loc) • 5.12 kB
TypeScript
/// <reference types="node" />
import { LocalStorage, ExternalConnection } from './AdapterExporter';
import { JSONFormatter, ShardCollection } from './ConstructorExporter';
import { EventEmitter } from "node:events";
export declare class Database extends EventEmitter {
adapter: LocalStorage | ExternalConnection;
tablePath: string;
ip: string | undefined;
port: string | undefined;
protected alerts: boolean;
protected ignore: boolean;
protected useTabulation: JSONFormatter | undefined;
type: ShardCollection | 'SingleFile';
/**
* The main class of an insta-write database app.
* @example const database = new Database(adapter, { alerts: true, overwrite: false, useTabulation: tabulationResolvable });
*
* @param adapter
* @param settings
* @param alerts - Alert writes and removes to the console.
* @param useTabulation - Use tabulation when formatting json file
*/
constructor(adapter: LocalStorage | ExternalConnection, settings?: {
alerts?: boolean | undefined;
ignoreDeprecations?: boolean | undefined;
useTabulation?: JSONFormatter | undefined;
type?: ShardCollection | 'SingleFile' | undefined;
} | undefined);
private get;
private put;
/**
* Creates a new line in database.
* @note It's async, so it returns a promise.
* @warning Pointers are not allowed in this method.
* @example const result = await Database.create('table', { key: "example", value: "exampleValue" })
* @param action.resolve resolves value of this key after it's creation in database.
* @returns {Promise<any|void>}
* @async
* @deprecated This method is marked as deprecated. Use create() instead.
*/
write(table: string, action: {
key: string;
value: any;
resolve?: boolean | undefined;
}): Promise<any | void>;
/**
* Creates a new line in database.
* @note It's async, so it returns a promise.
* @warning Pointers are not allowed in this method.
* @example const result = await Database.create('table', { key: "example", value: "exampleValue" })
* @param action.resolve resolves value of this key after it's creation in database.
* @returns {Promise<any|void>}
* @async
*/
create(table: string, action: {
key: string;
value: any;
resolve?: boolean | undefined;
}): Promise<any | void>;
/**
* Edits a line in database.
* @note It's async, so it returns a promise.
* @warning "~" pointer is not allowed here.
* @example const result = await Database.edit('table', { key: "example", value: "exampleValue" })
* @param action.newline if true and if this key/subkey does not exist, it creates it instead.
* @param action.resolve resolves value of this key after changes in database.
* @returns {Promise<any|void>}
* @async
*/
edit(table: string, action: {
key: string;
value: any;
newline?: boolean | undefined;
resolve?: boolean | undefined;
}): Promise<any | void>;
/**
* Removes a line in database or subkey.
* @note It's async, so it returns a promise.
* @warning "~" pointer is not allowed here.
* @example const result = await Database.remove('table', { key: "example" })
* @note you can use it without await, because it's a void method.
* @returns {Promise<void>}
* @async
*/
remove(table: string, action: {
key: string;
}): Promise<void>;
/**
* Returns a value of this key.
* @warning Any pointer is allowed.
* @example const result = Database.read('table', { key: "example" })
* @note And it should return value of this key. Otherwise it returns undefined.
* @returns {any|object|undefined}
*/
read(table: string, action: {
key: string;
}): any | object | undefined;
/**
* Checks if this key exists in this table.
* @note Returns boolean value.
* @warning "~" pointer is not allowed here. If using "." pointer it returns an object
* @example const result = Database.check('table', { key: "example" })
* @note And it should return true, if exists. Otherwise it returns false.
* @returns {Boolean}
*/
check(table: string, action: {
key: string;
}): boolean;
/**
* Same as Database#check(), but resolvable.
* @note It means that it returns a promise. If key is not undefined, it resolves it and can be accessed with await or .then() construction.
* @warning "~" pointer is not allowed here. If using "." pointer it returns an object
* @example const result = await Database.checkres('table', { key: "example" })
* @note And it should return value of this key, if exists. Otherwise it returns undefined.
* @returns {Promise<any|undefined>}
* @async
*/
checkres(table: string, action: {
key: string;
}): Promise<any | undefined>;
}