refactor(desktop): organize lib modules by domain
This commit is contained in:
1 parent
90f0594e93
commit
7e7c4944e9
700 files changed
+1292
-1264
No files matched your search
@@ -0,0 +1,18 @@
|
||||
import * as api from "@/lib/backend/api";
|
||||
|
||||
export const SQLITE_DATABASE_FILE_EXTENSIONS = ["db", "db3", "sqlite", "sqlite3", "sqlitedb"];
|
||||
|
||||
const SQLITE_DATABASE_EXTENSION_SET = new Set(SQLITE_DATABASE_FILE_EXTENSIONS.map((extension) => `.${extension}`));
|
||||
|
||||
export function databaseTypeFromKnownExtension(path: string): "sqlite" | "duckdb" | null {
|
||||
const lower = path.toLowerCase();
|
||||
if (lower.endsWith(".duckdb")) return "duckdb";
|
||||
if ([...SQLITE_DATABASE_EXTENSION_SET].some((extension) => lower.endsWith(extension))) return "sqlite";
|
||||
return null;
|
||||
}
|
||||
|
||||
export async function detectDatabaseFileType(path: string): Promise<"sqlite" | "duckdb" | null> {
|
||||
const knownType = databaseTypeFromKnownExtension(path);
|
||||
if (knownType) return knownType;
|
||||
return (await api.isSqliteDatabaseFile(path).catch(() => false)) ? "sqlite" : null;
|
||||
}
|
||||
Reference in new issue
Block a user