Skip to content

Commit

Permalink
Fix local development with linked core-db (#627)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxcnunes authored Apr 3, 2021
1 parent 210cfb6 commit e645051
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 26 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
"lodash.defaultsdeep": "^4.6.0",
"lodash.omit": "^4.5.0",
"mkdirp": "^1.0.4",
"sqlectron-db-core": "^0.8.1",
"sqlectron-db-core": "^0.9.0",
"uuid": "^8.3.2",
"valida2": "^2.6.1"
},
Expand Down
1 change: 0 additions & 1 deletion scripts/link-sqlectron-db-core.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ set -e

rm -rf node_modules/sqlectron-db-core
npm link ../sqlectron-db-core
npm run postinstall # rebuild native deps
16 changes: 10 additions & 6 deletions src/browser/core/db.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { WebContents, BrowserWindow, IpcMainInvokeEvent, IpcMainEvent } from 'electron';

import * as db from 'sqlectron-db-core';
import { ADAPTERS } from 'sqlectron-db-core';
import { Database, setSelectLimit } from 'sqlectron-db-core/database';
import type { Adapter } from 'sqlectron-db-core/adapters';
import type { QueryRowResult } from 'sqlectron-db-core/adapters/abstract_adapter';
import type { DatabaseFilter, SchemaFilter } from 'sqlectron-db-core/filters';
import { Server as DBServer, LegacyServerConfig } from 'sqlectron-db-core/server';
import { ADAPTERS, setSelectLimit } from 'sqlectron-db-core';
import type {
Database,
Adapter,
QueryRowResult,
DatabaseFilter,
SchemaFilter,
Server as DBServer,
LegacyServerConfig,
} from 'sqlectron-db-core';
import omit from 'lodash.omit';
import { Server } from '../../common/types/server';
import { SqlectronDB } from '../../common/types/api';
Expand Down
2 changes: 1 addition & 1 deletion src/browser/core/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { setLogger } from 'sqlectron-db-core/logger';
import { setLogger } from 'sqlectron-db-core';
import { getConn } from './db';
import * as config from './config';
import * as servers from './servers';
Expand Down
2 changes: 1 addition & 1 deletion src/browser/core/limit.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
setSelectLimit as internalSet,
clearSelectLimit as internalClear,
} from 'sqlectron-db-core/database';
} from 'sqlectron-db-core';
import * as config from './config';

export async function setSelectLimit(): Promise<void> {
Expand Down
25 changes: 20 additions & 5 deletions src/browser/core/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ import path from 'path';
import mkdirp from 'mkdirp';
import envPaths from 'env-paths';

import { readFile, resolveHomePathToAbsolute } from 'sqlectron-db-core/utils';

export { resolveHomePathToAbsolute } from 'sqlectron-db-core/utils';

let configPath = '';

export function getConfigPath(): string {
Expand Down Expand Up @@ -65,7 +61,18 @@ export function writeJSONFileSync<T>(filename: string, data: T): void {
}

export function readJSONFile<T>(filename: string): Promise<T> {
return readFile(filename).then((data) => JSON.parse(data));
const filePath = resolveHomePathToAbsolute(filename);
return new Promise((resolve, reject) => {
fs.readFile(path.resolve(filePath), { encoding: 'utf-8' }, (err, data) => {
if (err) return reject(err);
try {
const parsed = JSON.parse(data);
resolve(parsed);
} catch (err) {
reject(err);
}
});
});
}

export function readJSONFileSync<T>(filename: string): T {
Expand All @@ -81,3 +88,11 @@ export function createParentDirectory(filename: string): void {
export function createParentDirectorySync(filename: string): void {
mkdirp.sync(path.dirname(filename));
}

export function resolveHomePathToAbsolute(filename: string): string {
if (!/^~\//.test(filename)) {
return filename;
}

return path.join(homedir(), filename.substring(2));
}
4 changes: 1 addition & 3 deletions src/common/types/api.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import type { IpcMainInvokeEvent, IpcMainEvent } from 'electron';
import type { Config } from './config';
import type { Server } from './server';
import type { Adapter } from 'sqlectron-db-core/adapters';
import type { QueryRowResult } from 'sqlectron-db-core/adapters/abstract_adapter';
import type { SchemaFilter, DatabaseFilter } from 'sqlectron-db-core/filters';
import type { Adapter, QueryRowResult, SchemaFilter, DatabaseFilter } from 'sqlectron-db-core';

export interface MenuOptions {
menuItems: Array<MenuItem>;
Expand Down
3 changes: 1 addition & 2 deletions src/common/types/database.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export type { Database } from 'sqlectron-db-core/database';
export type { SchemaFilter, DatabaseFilter } from 'sqlectron-db-core/filters';
export type { Database, SchemaFilter, DatabaseFilter } from 'sqlectron-db-core';

0 comments on commit e645051

Please sign in to comment.