tiny-essentials
Version:
Collection of small, essential scripts designed to be used across various projects. These simple utilities are crafted for speed, ease of use, and versatility.
32 lines • 1.73 kB
text/typescript
/**
* Executes a directional query (next or previous) based on a position value and timestamp, returning a single row.
*
* @async
* @param {Record<string, any>} db - The database instance with a `.query(sql, params)` method.
* @param {Object} tiny_search - Configuration object for the query.
* @param {string} tiny_search.select - SQL SELECT fields.
* @param {string} tiny_search.from - SQL FROM clause.
* @param {string} [tiny_search.where] - Optional WHERE clause (without 'WHERE') to filter results.
* @param {Array<*>} tiny_search.params - Parameters for the query placeholders.
* @param {*} tiny_search.position - Value to compare in the directional filter (typically an ID or timestamp).
* @param {boolean} [tiny_search.direction_r=false] - If `true`, selects previous record (uses `<`), otherwise selects next (`>`).
* @param {Object} tiny_search.database - Object with database structure details.
* @param {string} tiny_search.database.name - The table name or alias used in the query.
* @param {string} tiny_search.database.timeVar - Column name used for ordering chronologically (e.g., `"created_at"`).
* @param {string} tiny_search.database.positionVar - Column name used for the directional condition (e.g., `"id"`).
* @returns {Promise<Object|null>} Resolves with the selected row or `null` if none is found.
*/
export default function nextPrev(db: Record<string, any>, tiny_search: {
select: string;
from: string;
where?: string | undefined;
params: Array<any>;
position: any;
direction_r?: boolean | undefined;
database: {
name: string;
timeVar: string;
positionVar: string;
};
}): Promise<Object | null>;
//# sourceMappingURL=nextPrev.d.mts.map