GoodDB
    Preparing search index...

    Class GoodDB

    The main class for the GoodDB package

    const db = new GoodDB(new JSONDriver({ path: './database.json' }));
    
    const db = new GoodDB(new MongoDBDriver({ uri: "..." }));
    await db.connect();

    Implements

    Index

    Constructors

    Properties

    add: (
        key: string,
        value: number,
        options?: methodOptions,
    ) => number | Promise<number>

    Add a number to the value stored in a key.

    Type Declaration

      • (key: string, value: number, options?: methodOptions): number | Promise<number>
      • Parameters

        • key: string

          The key of the value to add to.

        • value: number

          The number to add.

        • Optionaloptions: methodOptions

          The options to use.

        Returns number | Promise<number>

        The new value or a promise that resolves to the new value.

    all: (type?: "object" | "array") => any

    Get all the data in the database.

    Type Declaration

      • (type?: "object" | "array"): any
      • Parameters

        • Optionaltype: "object" | "array"

          The type of data to return ('object' or 'array').

        Returns any

        All the data or a promise that resolves to all the data.

    cacheIsEnabled: boolean
    cacheService: LRUCache | undefined
    clear: () => boolean | Promise<boolean>

    Clear the database.

    Type Declaration

      • (): boolean | Promise<boolean>
      • Returns boolean | Promise<boolean>

        A boolean indicating the success of the operation or a promise that resolves to a boolean.

    delete: (key: string, options?: methodOptions) => boolean | Promise<boolean>

    Delete a key and its associated value.

    Type Declaration

      • (key: string, options?: methodOptions): boolean | Promise<boolean>
      • Parameters

        • key: string

          The key to delete.

        • Optionaloptions: methodOptions

          The options to use.

        Returns boolean | Promise<boolean>

        A boolean indicating the success of the operation or a promise that resolves to a boolean.

    deleteMany: (
        keys: string[],
        options?: methodOptions,
    ) => boolean | Promise<boolean>

    Delete multiple keys at once.

    Type Declaration

      • (keys: string[], options?: methodOptions): boolean | Promise<boolean>
      • Parameters

        • keys: string[]

          An array of keys to delete.

        • Optionaloptions: methodOptions

          The options to use.

        Returns boolean | Promise<boolean>

        A boolean indicating the success of the operation or a promise that resolves to a boolean.

    distinct: (
        key: string,
        value?: (value: any, index: number, obj: any[]) => any,
        options?: methodOptions,
    ) => boolean | Promise<boolean>

    Get distinct values from an array stored in a key.

    Type Declaration

      • (
            key: string,
            value?: (value: any, index: number, obj: any[]) => any,
            options?: methodOptions,
        ): boolean | Promise<boolean>
      • Parameters

        • key: string

          The key of the array to get distinct values from.

        • Optionalvalue: (value: any, index: number, obj: any[]) => any

          The value or callback function to use for getting distinct values.

        • Optionaloptions: methodOptions

          The options to use.

        Returns boolean | Promise<boolean>

        A boolean indicating whether any value was found or a promise that resolves to a boolean.

    double: (key: string, options?: methodOptions) => number | Promise<number>

    Double the value stored in a key.

    Type Declaration

      • (key: string, options?: methodOptions): number | Promise<number>
      • Parameters

        • key: string

          The key of the value to double.

        • Optionaloptions: methodOptions

          The options to use.

        Returns number | Promise<number>

        The new value or a promise that resolves to the new value.

    driver: Drivers
    endsWith: (key: string, options?: methodOptions) => any

    Check if a key ends with a specific value.

    Type Declaration

      • (key: string, options?: methodOptions): any
      • Parameters

        • key: string

          The key to check.

        • Optionaloptions: methodOptions

          The options to use.

        Returns any

        The value or a promise that resolves to the value.

    filter: (
        key: string,
        callback: (value: any, index: number, obj: any[]) => unknown,
        options?: methodOptions,
    ) => any[] | Promise<any[]>

    Filter values in an array stored in a key.

    Type Declaration

      • (
            key: string,
            callback: (value: any, index: number, obj: any[]) => unknown,
            options?: methodOptions,
        ): any[] | Promise<any[]>
      • Parameters

        • key: string

          The key of the array to filter.

        • callback: (value: any, index: number, obj: any[]) => unknown

          The callback filter function to use.

        • Optionaloptions: methodOptions

          The options to use.

        Returns any[] | Promise<any[]>

        An array of filtered values or a promise that resolves to an array.

    find: (
        key: string,
        callback: (value: any, index: number, obj: any[]) => unknown,
        options?: methodOptions,
    ) => any

    Find values in an array stored in a key that satisfy a callback function.

    Type Declaration

      • (
            key: string,
            callback: (value: any, index: number, obj: any[]) => unknown,
            options?: methodOptions,
        ): any
      • Parameters

        • key: string

          The key of the array to find values in.

        • callback: (value: any, index: number, obj: any[]) => unknown

          The callback function to use for finding values.

        • Optionaloptions: methodOptions

          The options to use.

        Returns any

        The value or a promise that resolves to the value.

    findAndUpdate: (
        key: string,
        findCallback: (value: any, index: number, obj: any[]) => unknown,
        updateCallback: (value: any, index: number, obj: any[]) => any,
        options?: methodOptions,
    ) => any

    Find a value in an array and update it.

    Type Declaration

      • (
            key: string,
            findCallback: (value: any, index: number, obj: any[]) => unknown,
            updateCallback: (value: any, index: number, obj: any[]) => any,
            options?: methodOptions,
        ): any
      • Parameters

        • key: string

          The key of the array to search.

        • findCallback: (value: any, index: number, obj: any[]) => unknown

          The callback function to find the element.

        • updateCallback: (value: any, index: number, obj: any[]) => any

          The callback function to update the found element.

        • Optionaloptions: methodOptions

          The options to use.

        Returns any

        The updated element or undefined if not found, or a promise that resolves to the result.

    findAndUpdateMany: (
        key: string,
        findCallback: (value: any, index: number, obj: any[]) => unknown,
        updateCallback: (value: any, index: number, obj: any[]) => any,
        options?: methodOptions,
    ) => any[] | Promise<any[]>

    Find multiple values in an array and update them.

    Type Declaration

      • (
            key: string,
            findCallback: (value: any, index: number, obj: any[]) => unknown,
            updateCallback: (value: any, index: number, obj: any[]) => any,
            options?: methodOptions,
        ): any[] | Promise<any[]>
      • Parameters

        • key: string

          The key of the array to search.

        • findCallback: (value: any, index: number, obj: any[]) => unknown

          The callback function to find the elements.

        • updateCallback: (value: any, index: number, obj: any[]) => any

          The callback function to update the found elements.

        • Optionaloptions: methodOptions

          The options to use.

        Returns any[] | Promise<any[]>

        An array of updated elements or a promise that resolves to an array of updated elements.

    get: (key: string, options?: methodOptions) => any

    Get the value associated with a key.

    Type Declaration

      • (key: string, options?: methodOptions): any
      • Parameters

        • key: string

          The key to get the value from.

        • Optionaloptions: methodOptions

          The options to use.

        Returns any

        The value associated with the key or a promise that resolves to the value.

    getMany: (
        keys: string[],
        options?: methodOptions,
    ) => Record<string, any> | Promise<Record<string, any>>

    Get multiple values by their keys at once.

    Type Declaration

      • (
            keys: string[],
            options?: methodOptions,
        ): Record<string, any> | Promise<Record<string, any>>
      • Parameters

        • keys: string[]

          An array of keys to get.

        • Optionaloptions: methodOptions

          The options to use.

        Returns Record<string, any> | Promise<Record<string, any>>

        An object with key-value pairs or a promise that resolves to an object with key-value pairs.

    has: (key: string, options?: methodOptions) => boolean | Promise<boolean>

    Check if a key exists.

    Type Declaration

      • (key: string, options?: methodOptions): boolean | Promise<boolean>
      • Parameters

        • key: string

          The key to check.

        • Optionaloptions: methodOptions

          The options to use.

        Returns boolean | Promise<boolean>

        A boolean indicating whether the key exists or a promise that resolves to a boolean.

    includes: (key: string, options?: methodOptions) => any

    Check if a key includes a specific value.

    Type Declaration

      • (key: string, options?: methodOptions): any
      • Parameters

        • key: string

          The key to check.

        • Optionaloptions: methodOptions

          The options to use.

        Returns any

        The value or a promise that resolves to the value.

    isAsync: boolean
    keys: () => string[] | Promise<string[]>

    Get all the keys in the database.

    Type Declaration

      • (): string[] | Promise<string[]>
      • Returns string[] | Promise<string[]>

        An array of keys or a promise that resolves to an array of keys.

    math: (
        key: string,
        mathSign: MathSigns,
        value: number,
        options?: methodOptions,
    ) => number | Promise<number>

    Perform a mathematical operation on the value stored in a key.

    Type Declaration

      • (
            key: string,
            mathSign: MathSigns,
            value: number,
            options?: methodOptions,
        ): number | Promise<number>
      • Parameters

        • key: string

          The key of the value to perform the operation on.

        • mathSign: MathSigns

          The mathematical sign to use for the operation.

        • value: number

          The number to use for the operation.

        • Optionaloptions: methodOptions

          The options to use.

        Returns number | Promise<number>

        The new value or a promise that resolves to the new value.

    multiply: (
        key: string,
        value: number,
        options?: methodOptions,
    ) => number | Promise<number>

    Multiply the value stored in a key by a number.

    Type Declaration

      • (key: string, value: number, options?: methodOptions): number | Promise<number>
      • Parameters

        • key: string

          The key of the value to multiply.

        • value: number

          The number to multiply by.

        • Optionaloptions: methodOptions

          The options to use.

        Returns number | Promise<number>

        The new value or a promise that resolves to the new value.

    nested: { isEnabled: boolean; nested: string }
    options?: goodDBOptions
    pop: (key: string, options?: methodOptions) => any

    Remove and return the last element of an array stored in a key.

    Type Declaration

      • (key: string, options?: methodOptions): any
      • Parameters

        • key: string

          The key of the array to pop the value from.

        • Optionaloptions: methodOptions

          The options to use.

        Returns any

        The popped value or a promise that resolves to the popped value.

    pull: (
        key: string,
        valueOrCallback: (e: any, i: number, a: any) => any,
        pullAll?: boolean,
        options?: methodOptions,
    ) => boolean | Promise<boolean>

    Remove one or all occurrences of a value from an array stored in a key.

    Type Declaration

      • (
            key: string,
            valueOrCallback: (e: any, i: number, a: any) => any,
            pullAll?: boolean,
            options?: methodOptions,
        ): boolean | Promise<boolean>
      • Parameters

        • key: string

          The key of the array to pull the value from.

        • valueOrCallback: (e: any, i: number, a: any) => any

          The value or callback function to use to pull the value.

        • OptionalpullAll: boolean

          Whether to pull all occurrences or just the first one.

        • Optionaloptions: methodOptions

          The options to use.

        Returns boolean | Promise<boolean>

        A boolean indicating whether any value was pulled or a promise that resolves to a boolean.

    push: (
        key: string,
        value: any,
        options?: methodOptions,
    ) => number | Promise<number>

    Push a value to an array stored in a key.

    Type Declaration

      • (key: string, value: any, options?: methodOptions): number | Promise<number>
      • Parameters

        • key: string

          The key of the array to push the value to.

        • value: any

          The value to push.

        • Optionaloptions: methodOptions

          The options to use.

        Returns number | Promise<number>

        The new length of the array or a promise that resolves to the new length.

    set: (
        key: string,
        value: any,
        options?: methodOptions,
    ) => boolean | Promise<boolean>

    Set a value to a key.

    Type Declaration

      • (key: string, value: any, options?: methodOptions): boolean | Promise<boolean>
      • Parameters

        • key: string

          The key to set the value to.

        • value: any

          The value to set.

        • Optionaloptions: methodOptions

          The options to use.

        Returns boolean | Promise<boolean>

        A boolean indicating the success of the operation or a promise that resolves to a boolean.

    setMany: (
        data: Record<string, any>,
        options?: methodOptions,
    ) => boolean | Promise<boolean>

    Set multiple key-value pairs at once.

    Type Declaration

      • (data: Record<string, any>, options?: methodOptions): boolean | Promise<boolean>
      • Parameters

        • data: Record<string, any>

          An object with key-value pairs to set.

        • Optionaloptions: methodOptions

          The options to use.

        Returns boolean | Promise<boolean>

        A boolean indicating the success of the operation or a promise that resolves to a boolean.

    shift: (key: string, options?: methodOptions) => any

    Remove and return the first element of an array stored in a key.

    Type Declaration

      • (key: string, options?: methodOptions): any
      • Parameters

        • key: string

          The key of the array to shift the value from.

        • Optionaloptions: methodOptions

          The options to use.

        Returns any

        The shifted value or a promise that resolves to the shifted value.

    size: (key: string, options?: methodOptions) => number | Promise<number>

    Get the size of the value stored in a key.

    Type Declaration

      • (key: string, options?: methodOptions): number | Promise<number>
      • Parameters

        • key: string

          The key of the value to get the size of.

        • Optionaloptions: methodOptions

          The options to use.

        Returns number | Promise<number>

        The size of the value or a promise that resolves to the size.

    startsWith: (key: string, options?: methodOptions) => any

    Check if a key starts with a specific value.

    Type Declaration

      • (key: string, options?: methodOptions): any
      • Parameters

        • key: string

          The key to check.

        • Optionaloptions: methodOptions

          The options to use.

        Returns any

        The value or a promise that resolves to the value.

    subtract: (
        key: string,
        value: number,
        options?: methodOptions,
    ) => number | Promise<number>

    Subtract a number from the value stored in a key.

    Type Declaration

      • (key: string, value: number, options?: methodOptions): number | Promise<number>
      • Parameters

        • key: string

          The key of the value to subtract from.

        • value: number

          The number to subtract.

        • Optionaloptions: methodOptions

          The options to use.

        Returns number | Promise<number>

        The new value or a promise that resolves to the new value.

    table: (name: string) => GoodDB | Promise<GoodDB>

    Get a table from the database.

    Type Declaration

      • (name: string): GoodDB | Promise<GoodDB>
      • Parameters

        • name: string

          The name of the table.

        Returns GoodDB | Promise<GoodDB>

        An instance of the IGoodDB interface or a promise that resolves to an instance of the IGoodDB interface.

    tableName: string
    type: (key: string, options?: methodOptions) => string | Promise<string>

    Get the type of the value stored in a key.

    Type Declaration

      • (key: string, options?: methodOptions): string | Promise<string>
      • Parameters

        • key: string

          The key of the value to get the type of.

        • Optionaloptions: methodOptions

          The options to use.

        Returns string | Promise<string>

        The type of the value or a promise that resolves to the type.

    unshift: (
        key: string,
        value: any,
        options?: methodOptions,
    ) => number | Promise<number>

    Add a value to the beginning of an array stored in a key.

    Type Declaration

      • (key: string, value: any, options?: methodOptions): number | Promise<number>
      • Parameters

        • key: string

          The key of the array to unshift the value to.

        • value: any

          The value to unshift.

        • Optionaloptions: methodOptions

          The options to use.

        Returns number | Promise<number>

        The new length of the array or a promise that resolves to the new length.

    values: () => any[] | Promise<any[]>

    Get all the values in the database.

    Type Declaration

      • (): any[] | Promise<any[]>
      • Returns any[] | Promise<any[]>

        An array of values or a promise that resolves to an array of values.

    Accessors

    • get getNestedOptions(): { nested: string; nestedIsEnabled: boolean }

      Returns { nested: string; nestedIsEnabled: boolean }

    Methods

    • Parameters

      • key: string

      Returns void

    • Connect to the database.

      Returns Promise<boolean>

      A promise that resolves to a boolean indicating the success of the connection.

    • Disconnect from the database.

      Returns Promise<boolean>

      A promise that resolves to a boolean indicating the success of the disconnection.