feat(storage): add comprehensive database management interface
- Add new storage commands module with full CRUD operations - Implement SQLite database viewer with table browsing, search, and pagination - Add row editing, insertion, and deletion capabilities - Include SQL query editor for advanced operations - Add database reset functionality with confirmation dialogs - Export storage API methods for frontend integration - Add storage tab to settings with modern UI components - Implement comprehensive error handling and loading states - Add tooltips for truncated content and responsive design - Include proper TypeScript interfaces for all data structures This enables users to directly interact with the SQLite database through a user-friendly interface, providing transparency and control over stored data.
This commit is contained in:
134
src/lib/api.ts
134
src/lib/api.ts
@@ -1511,5 +1511,139 @@ export const api = {
|
||||
}
|
||||
},
|
||||
|
||||
// Storage API methods
|
||||
|
||||
/**
|
||||
* Lists all tables in the SQLite database
|
||||
* @returns Promise resolving to an array of table information
|
||||
*/
|
||||
async storageListTables(): Promise<any[]> {
|
||||
try {
|
||||
return await invoke<any[]>("storage_list_tables");
|
||||
} catch (error) {
|
||||
console.error("Failed to list tables:", error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Reads table data with pagination
|
||||
* @param tableName - Name of the table to read
|
||||
* @param page - Page number (1-indexed)
|
||||
* @param pageSize - Number of rows per page
|
||||
* @param searchQuery - Optional search query
|
||||
* @returns Promise resolving to table data with pagination info
|
||||
*/
|
||||
async storageReadTable(
|
||||
tableName: string,
|
||||
page: number,
|
||||
pageSize: number,
|
||||
searchQuery?: string
|
||||
): Promise<any> {
|
||||
try {
|
||||
return await invoke<any>("storage_read_table", {
|
||||
tableName,
|
||||
page,
|
||||
pageSize,
|
||||
searchQuery,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Failed to read table:", error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Updates a row in a table
|
||||
* @param tableName - Name of the table
|
||||
* @param primaryKeyValues - Map of primary key column names to values
|
||||
* @param updates - Map of column names to new values
|
||||
* @returns Promise resolving when the row is updated
|
||||
*/
|
||||
async storageUpdateRow(
|
||||
tableName: string,
|
||||
primaryKeyValues: Record<string, any>,
|
||||
updates: Record<string, any>
|
||||
): Promise<void> {
|
||||
try {
|
||||
return await invoke<void>("storage_update_row", {
|
||||
tableName,
|
||||
primaryKeyValues,
|
||||
updates,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Failed to update row:", error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Deletes a row from a table
|
||||
* @param tableName - Name of the table
|
||||
* @param primaryKeyValues - Map of primary key column names to values
|
||||
* @returns Promise resolving when the row is deleted
|
||||
*/
|
||||
async storageDeleteRow(
|
||||
tableName: string,
|
||||
primaryKeyValues: Record<string, any>
|
||||
): Promise<void> {
|
||||
try {
|
||||
return await invoke<void>("storage_delete_row", {
|
||||
tableName,
|
||||
primaryKeyValues,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Failed to delete row:", error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Inserts a new row into a table
|
||||
* @param tableName - Name of the table
|
||||
* @param values - Map of column names to values
|
||||
* @returns Promise resolving to the last insert row ID
|
||||
*/
|
||||
async storageInsertRow(
|
||||
tableName: string,
|
||||
values: Record<string, any>
|
||||
): Promise<number> {
|
||||
try {
|
||||
return await invoke<number>("storage_insert_row", {
|
||||
tableName,
|
||||
values,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Failed to insert row:", error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Executes a raw SQL query
|
||||
* @param query - SQL query string
|
||||
* @returns Promise resolving to query result
|
||||
*/
|
||||
async storageExecuteSql(query: string): Promise<any> {
|
||||
try {
|
||||
return await invoke<any>("storage_execute_sql", { query });
|
||||
} catch (error) {
|
||||
console.error("Failed to execute SQL:", error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Resets the entire database
|
||||
* @returns Promise resolving when the database is reset
|
||||
*/
|
||||
async storageResetDatabase(): Promise<void> {
|
||||
try {
|
||||
return await invoke<void>("storage_reset_database");
|
||||
} catch (error) {
|
||||
console.error("Failed to reset database:", error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
};
|
||||
|
Reference in New Issue
Block a user