import { SuperArray } from "./SuperArray"; type Constructor = new (...args: any[]) => T; /** * A class representing a table of data with various utility methods for manipulation and analysis. */ export declare class DBTable { protected _data: rowInterface[]; protected _meta: { columnNames: string[]; columnTypes: any; }; protected _instanceID: string; protected _formatter?: (row: any) => rowInterface; /** * Creates an instance of DBTable. * @param data Array of objects representing the table rows * @param meta Optional metadata object * @param formatter Optional function to format/transform each row */ constructor(jsonTable?: rowInterface[], metaData?: any, formatter?: (row: any) => rowInterface); /** * currentConstructor - Reference to the constructor function of the current class instance * * This property holds the constructor function of the current DBTable instance. * It is used to ensure that methods which return new instances of the class * will create objects of the correct type, especially when working with subclasses. * * When methods like whereColumnGreaterThan() or whereColumnLessThan() create * new instances, using this.currentConstructor ensures that: * 1. The correct constructor is used for subclass instances * 2. Prototype chain is preserved * 3. Static methods/properties are properly inherited * 4. Method chaining works correctly with the right type * * Example: * class MyCustomTable extends DBTable { * customMethod() { ... } * } * * When a MyCustomTable instance calls whereColumnGreaterThan(), * currentConstructor ensures the returned instance is also MyCustomTable * * @see Used in: whereColumnGreaterThan, whereColumnLessThan, etc. */ protected get currentConstructor(): Constructor; /** * Returns the column types mapping. * @returns {{[key:string]: any}} An object mapping column names to their inferred types. */ getColumnTypes(): any; /** * Returns an array of the table’s column names. * @returns {string[]} The sorted list of column names. */ getColumnNames(): string[]; updateMeta(): void; /** * Number of rows in the table */ get count(): number; /** * Gets the underlying data array. */ get data(): rowInterface[]; /** * Returns a new DBTable containing only distinct rows based on all column values. * Duplicate rows are removed by comparing all fields in each row. * * @returns {DBTable} A new DBTable instance with all duplicate rows removed. * * @example * const uniqueRows = table.distinct(); */ distinct(): this; /** * * @param {string} columnName * @param amount defaults to 1 * @return {DBTable} */ incrementColumn(columnName: string, amount?: any): this; /** * Unions current data with data that is passed in * @returns a new DBTable with the 'unioned' data * @param data - can be a DBTable, a row from a table, or an array of rows */ union(data: DBTable | rowInterface[] | rowInterface): this; /** * * @param {DBTable} table * @param {string} column * @param {boolean} overwrite * @return {DBTable} */ mergeTableBy(table: DBTable, column: keyof rowInterface, overwrite?: boolean): DBTable; /** * * @param column * @param order */ orderBy(column: keyof rowInterface, order?: "ASC" | "DESC"): this; /** * Returns a new `DBTable` with the rows randomly shuffled. * The original table remains unchanged. * @returns {DBTable} A shuffled copy of the table. */ shuffle(): this; /** * Removes a column from the table. * The method clears the column name list, deletes the type entry and removes the property from every row. * @param columnName - Name of the column to delete. * @returns {DBTable} The current instance for chaining. */ removeColumn(columnName: keyof rowInterface | string): this; /** * Returns a new `DBTable` containing a subset of the columns from the original table. * * This method allows you to select specific columns from the table, creating a new table with only those columns. * It is useful for reducing the amount of data processed or displayed, or for creating views tailored to specific needs. * * @param {string[]} columns - An array of column names to include in the new table. * @returns {DBTable} A new `DBTable` containing only the selected columns. Returns a new instance; does not modify the original table. * * @example * // Select only the 'name' and 'age' columns * const selectedTable = dbTable.select(['name', 'age']); * * @example * // Select a single column * const nameTable = dbTable.select(['name']); */ select(columns: (keyof rowInterface)[], distinct?: boolean): DBTable>; /** * Sets the specified column to a given value for all rows in the table. * This mutates the current instance and returns it for chaining. * @param {keyof rowInterface} column - The name of the column to update. * @param {*} value - The value to assign to every row's column. * @returns {this} The updated table instance. */ setColumn(column: keyof rowInterface, value: any): this; /** * This is an experimental feature * @experimental * @param columnName */ listDistinctValues(columnName: keyof rowInterface, verbose?: boolean): DBTable<{ value: string; count: number; }>; /** * Returns the last N rows of the table. * * This method is helpful when you want to examine or analyze the last few entries in * a dataset, such as the most recent 10 records. * * @param n The number of rows to retrieve from the bottom of the table. * @returns A new `DBTable` containing the last `n` rows. * * @example * const recentRows = dbTable.bottom(10); // Get the last 10 rows */ bottom(count: number): this; /** * Returns the first N rows of the table. * * This method is useful when you want to quickly inspect or process the initial records * in a dataset, such as the top 10 results. * * @param n The number of rows to retrieve from the top of the table. * @returns A new `DBTable` containing the first `n` rows. * * @example * const topRows = dbTable.top(5); // Get the first 5 rows */ top(count: number): this; /** * Splits the data table into two new tables. * * This method divides the data into two parts based on a specified count. * The first table contains the first `count` rows, and the second table contains the remaining rows. * This is useful for dividing a dataset into training and testing sets, or for processing data in batches. * * @param {number} count - The number of rows to include in the first table. * @returns {[DBTable, DBTable]} An array containing two new `DBTable` instances: * - The first table contains the first `count` rows. * - The second table contains the remaining rows. */ split(count: number): this[]; /** * Skips a specified number of rows from the beginning of the data table. * @param {number} count - The number of rows to skip * @returns {this} A new instance with the skipped rows */ skip(count: number): this; /** * Filters rows where the specified column's value contains the given substring. * * @param column - The name of the column to check. Must be a key of the row interface. * @param value - The substring to search for within the column values. * @returns A new DBTable containing only the rows where the column value includes the specified substring. * * @example * // Filter rows where the "name" column contains "john" * const result = table.whereColumnContains("name", "john"); */ whereColumnContains(column: keyof rowInterface, value: number | string, caseSensitive?: boolean): this; /** * Filters the data table based on a condition. * @param {Function} callback - A function that returns true for rows to include * @returns {this} A new instance with the filtered rows */ filter(test: (row: rowInterface) => boolean): this; /** * Filters rows where the specified column equals a given value. * @param column - Column name to compare. * @param value - Value that the column must equal. * @returns {DBTable} A new table containing only matching rows. */ whereColumnEquals(column: keyof rowInterface, value: any): this; /** * * @param column * @param value * @return {DBTable} */ whereColumnNotEquals(column: keyof rowInterface, value: any): this; /** * * @param {string} column * @param {number | string} value * @return {this} */ whereColumnGreaterThanEquals(column: keyof rowInterface, value: number | string): this; /** * * @param {string} column * @param {number | string} value * @return {this} */ whereColumnLessThanEquals(column: keyof rowInterface, value: number | string): this; /** * Filters rows where the specified column’s value is greater than a given threshold. * The comparison uses JavaScript's native `>` operator, so numeric and string * values are compared according to their natural ordering. For strings this * means lexicographic order based on Unicode code points. * * @param column - The key of the column to compare. * @param value - The threshold; rows with a column value strictly greater than * this value will be included in the result. * @returns A new {@link DBTable} instance containing only the matching rows. */ whereColumnGreaterThan(column: keyof rowInterface, value: number | string): this; /** * Filters rows where the specified column’s value is less than a given threshold. * The comparison uses JavaScript's native `<` operator, so numeric and string * values are compared according to their natural ordering. For strings this * means lexicographic order based on Unicode code points. * * @param column - The key of the column to compare. * @param value - The threshold; rows with a column value strictly less than * this value will be included in the result. * @returns A new {@link DBTable} instance containing only the matching rows. */ whereColumnLessThan(column: keyof rowInterface, value: number | string): this; /** * Creates a {@link DBTable} instance from a JSON string. * The JSON is expected to be either an array of rows or an object * containing `data` and optional `meta` properties. If the input * contains a `data` property, that value will be used as the table * data; otherwise the entire parsed value is treated as the data. * * @param json - The JSON string to parse. An empty string defaults to an empty array. * @param formatter - Optional function applied to each row after parsing. * @returns A new {@link DBTable} instance populated with the parsed rows and metadata. */ static fromJson(json: string, formatter?: (row: any) => rowInterface): DBTable; /** * Serialises the table to a JSON string. * @param pretty Number of spaces for indentation (default 2). * @returns A JSON representation containing `data` and `meta`. */ toJSON(pretty?: number): string; /** * Converts the table’s columns into `SuperArray` instances. * Each column becomes a `SuperArray` containing all values from that column. * @returns {{[K in keyof rowInterface]: SuperArray}} An object mapping column names to their corresponding `SuperArray`. */ toSuperArrays(): { [K in keyof rowInterface]: SuperArray; }; /** * * @param input */ static fromSuperArrays(input: any): DBTable; } export {}; //# sourceMappingURL=DBTable.d.ts.map