mirror of
https://github.com/colanode/colanode.git
synced 2025-12-29 00:25:03 +01:00
Clean unused code
This commit is contained in:
@@ -2,11 +2,10 @@ import fs from 'fs';
|
||||
import { Kysely, Migration, Migrator, SqliteDialect } from 'kysely';
|
||||
import { AppDatabaseSchema } from '@/main/data/app/schema';
|
||||
import { WorkspaceDatabaseSchema } from '@/main/data/workspace/schema';
|
||||
import { buildSqlite } from '@/main/data/utils';
|
||||
import { appDatabaseMigrations } from '@/main/data/app/migrations';
|
||||
import { workspaceDatabaseMigrations } from '@/main/data/workspace/migrations';
|
||||
import { appDatabasePath, getWorkspaceDirectoryPath } from '@/main/utils';
|
||||
|
||||
import SQLite from 'better-sqlite3';
|
||||
class DatabaseService {
|
||||
private initPromise: Promise<void> | null = null;
|
||||
private readonly workspaceDatabases: Map<
|
||||
@@ -18,7 +17,7 @@ class DatabaseService {
|
||||
|
||||
constructor() {
|
||||
const dialect = new SqliteDialect({
|
||||
database: buildSqlite(appDatabasePath),
|
||||
database: this.buildSqlite(appDatabasePath),
|
||||
});
|
||||
|
||||
this.appDatabase = new Kysely<AppDatabaseSchema>({ dialect });
|
||||
@@ -102,7 +101,7 @@ class DatabaseService {
|
||||
}
|
||||
|
||||
const dialect = new SqliteDialect({
|
||||
database: buildSqlite(`${workspaceDir}/workspace.db`),
|
||||
database: this.buildSqlite(`${workspaceDir}/workspace.db`),
|
||||
});
|
||||
|
||||
const workspaceDatabase = new Kysely<WorkspaceDatabaseSchema>({
|
||||
@@ -140,6 +139,12 @@ class DatabaseService {
|
||||
|
||||
await migrator.migrateToLatest();
|
||||
}
|
||||
|
||||
private buildSqlite = (filename: string): SQLite.Database => {
|
||||
const database = new SQLite(filename);
|
||||
database.pragma('journal_mode = WAL');
|
||||
return database;
|
||||
};
|
||||
}
|
||||
|
||||
export const databaseService = new DatabaseService();
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
import SQLite from 'better-sqlite3';
|
||||
import { QueryResult } from 'kysely';
|
||||
import { isEqual } from 'lodash-es';
|
||||
|
||||
export const buildSqlite = (filename: string): SQLite.Database => {
|
||||
const database = new SQLite(filename);
|
||||
database.pragma('journal_mode = WAL');
|
||||
return database;
|
||||
};
|
||||
|
||||
export const extractTablesFromSql = (sql: string): string[] => {
|
||||
// A regex to match table names from SELECT, JOIN, UPDATE, INSERT, DELETE
|
||||
const regex = /\b(?:FROM|JOIN|INTO|UPDATE|TABLE)\s+["]?([a-zA-Z0-9_]+)["]?/gi;
|
||||
const matches = [...sql.matchAll(regex)].map((match) => match[1]);
|
||||
return matches;
|
||||
};
|
||||
|
||||
export const resultHasChanged = <R>(
|
||||
oldResult: QueryResult<R>,
|
||||
newResult: QueryResult<R>
|
||||
): boolean => {
|
||||
if (oldResult.rows.length !== newResult.rows.length) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (let i = 0; i < oldResult.rows.length; i++) {
|
||||
const oldRow = oldResult.rows[i];
|
||||
const newRow = newResult.rows[i];
|
||||
|
||||
if (!isEqual(oldRow, newRow)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
Reference in New Issue
Block a user