tiny-electron-essentials
Version:
A lightweight and modular utility library for Electron apps, offering simplified window management, tray support, IPC channels, and custom frameless window styling.
125 lines • 4.39 kB
text/typescript
export default TinyDb;
/**
* Executes an SQL command that modifies data (`INSERT`, `UPDATE`, `DELETE`)
* or runs any command without returning rows.
*/
export type SqlRun = (query: string, params: any[]) => Promise<any>;
/**
* Executes a SQL `SELECT` query that returns all matching rows.
*/
export type SqlAll = (query: string, params: any[]) => Promise<any[]>;
/**
* Executes a SQL `SELECT` query that returns a single row.
*/
export type SqlGet = (query: string, params: any[]) => Promise<any>;
/**
* Executes a generic SQL query. The result depends on the query type.
*/
export type SqlQuery = (query: string, params: any[]) => Promise<any>;
/**
* SqlManager represents the core interface for database interactions.
* It groups together the primary methods required to execute various types of SQL commands.
*/
export type SqlManager = {
get: SqlGet;
query: SqlQuery;
all: SqlAll;
run: SqlRun;
};
/**
* Executes an SQL command that modifies data (`INSERT`, `UPDATE`, `DELETE`)
* or runs any command without returning rows.
*
* @callback SqlRun
* @param {string} query - SQL query string.
* @param {any[]} params - Query parameters.
* @returns {Promise<any>} Result of the query execution.
*/
/**
* Executes a SQL `SELECT` query that returns all matching rows.
*
* @callback SqlAll
* @param {string} query - SQL query string.
* @param {any[]} params - Query parameters.
* @returns {Promise<any[]>} Array of matching rows.
*/
/**
* Executes a SQL `SELECT` query that returns a single row.
*
* @callback SqlGet
* @param {string} query - SQL query string.
* @param {any[]} params - Query parameters.
* @returns {Promise<any>} The first row matching the query.
*/
/**
* Executes a generic SQL query. The result depends on the query type.
*
* @callback SqlQuery
* @param {string} query - SQL query string.
* @param {any[]} params - Query parameters.
* @returns {Promise<any>} Result of the query.
*/
/**
* SqlManager represents the core interface for database interactions.
* It groups together the primary methods required to execute various types of SQL commands.
* @typedef {{ get: SqlGet; query: SqlQuery; all: SqlAll; run: SqlRun; }} SqlManager
*/
/**
* TinyDb provides a secure bridge between the Electron renderer process and the main process.
* It uses native `ipcRenderer.invoke` to perform database operations over IPC.
*
* This class exposes database-like methods (`run`, `all`, `get`, and `query`)
* to the renderer process using `contextBridge.exposeInMainWorld`.
*/
declare class TinyDb {
/**
* Creates a new TinyDb instance.
*
* @param {string} id - A unique identifier to namespace the IPC events.
* @throws {Error} If `id` is not a string.
*/
constructor(id: string);
/**
* Exposes the TinyDb API to the renderer process via `window[apiName]`.
*
* @param {string} [apiName='tinyDb'] - The name under which the API will be exposed in `window`.
* @throws {Error} If the API is already exposed.
* @throws {Error} If `apiName` is not a valid non-empty string.
*/
exposeInMainWorld(apiName?: string): void;
/**
* Executes an SQL command that modifies data (`INSERT`, `UPDATE`, `DELETE`)
* or runs any command without returning rows.
*
* @param {string} query - SQL query string.
* @param {any[]} params - Query parameters.
* @returns {Promise<any>}
*/
run(query: string, params: any[]): Promise<any>;
/**
* Executes a SQL `SELECT` query for multiple rows.
*
* @param {string} query - SQL query string.
* @param {any[]} params - Query parameters.
* @returns {Promise<any[]>} Array of matching rows.
*/
all(query: string, params: any[]): Promise<any[]>;
/**
* Executes a SQL `SELECT` query for a single row.
*
* @param {string} query - SQL query string.
* @param {any[]} params - Query parameters.
* @returns {Promise<any>} The first row matching the query.
*/
get(query: string, params: any[]): Promise<any>;
/**
* Executes a generic SQL query.
*
* @param {string} query - SQL query string.
* @param {any[]} params - Query parameters.
* @returns {Promise<any>} Result of the query.
*/
query(query: string, params: any[]): Promise<any>;
#private;
}
//# sourceMappingURL=TinyDb.d.mts.map