Checks if a history connection matches specified databases by ID or name. Reuse when filtering database connection histories in database tools.
// Source: https://github.com/t8y2/dbx | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
import type { HistoryConnectionFilter, HistoryDatabaseFilter } from "@/lib/backend/api";
export function historyConnectionHasSelectedDatabase(connection: HistoryConnectionFilter, databases: HistoryDatabaseFilter[]): boolean {
return databases.some((database) => {
if (!database.database) return false;
if (connection.connection_id || database.connection_id) {
return Boolean(connection.connection_id) && connection.connection_id === database.connection_id;
}
return Boolean(connection.connection_name) && connection.connection_name === database.connection_name;
});
}
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key