Skip to content

Commit e2faa5d

Browse files
committed
fix: refactor the driver
1 parent 35152ba commit e2faa5d

24 files changed

+57
-27
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"start:preload": "cross-env NODE_ENV=development TS_NODE_TRANSPILE_ONLY=true webpack --config ./.erb/configs/webpack.config.preload.dev.ts",
3030
"start:renderer": "cross-env NODE_ENV=development TS_NODE_TRANSPILE_ONLY=true webpack serve --config ./.erb/configs/webpack.config.renderer.dev.ts",
3131
"prepare": "cm-buildhelper src/language/sql/sql.ts",
32-
"test": "jest",
32+
"test": "jest --testPathIgnorePatterns=src/drivers",
33+
"test:driver": "jest src/drivers",
3334
"clean": "npx git-clear-branch",
3435
"type": "tsc --noEmit",
3536
"storybook": "storybook dev -p 6006",
File renamed without changes.
File renamed without changes.

src/drivers/common/MySQLCommonInterface.ts renamed to src/drivers/mysql/MySQLCommonInterface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
TableDefinitionSchema,
55
TableColumnSchema,
66
} from 'types/SqlSchema';
7-
import SQLCommonInterface from './SQLCommonInterface';
7+
import SQLCommonInterface from '../base/SQLCommonInterface';
88
import { SqlRunnerManager } from 'libs/SqlRunnerManager';
99
import { qb } from 'libs/QueryBuilder';
1010
import { QueryResult } from 'types/SqlResult';

src/drivers/MySQLConnection.ts renamed to src/drivers/mysql/MySQLConnection.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
} from 'types/SqlResult';
66
import SQLLikeConnection, {
77
DatabaseConnectionConfig,
8-
} from './SQLLikeConnection';
8+
} from '../base/SQLLikeConnection';
99
import {
1010
PoolConnection,
1111
createPool,
@@ -54,8 +54,6 @@ function mapHeaderType(column: ColumnDefinition): QueryResultHeader {
5454
type = { type: 'other' };
5555
}
5656

57-
console.log(column.name, column.type, type);
58-
5957
const databaseNameLength = column._buf[13];
6058
const databaseName =
6159
databaseNameLength > 0

src/drivers/test/query.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import MySQLConnection from 'drivers/mysql/MySQLConnection';
2+
import { qb } from 'libs/QueryBuilder';
3+
4+
const connection = new MySQLConnection(
5+
{
6+
database: 'querymaster_test',
7+
port: 3306,
8+
host: 'localhost',
9+
user: 'root',
10+
password: '123456',
11+
},
12+
() => {
13+
return;
14+
}
15+
);
16+
17+
afterAll(async () => {
18+
connection.close();
19+
});
20+
21+
test('test normal query', async () => {
22+
const r = await connection.query(
23+
qb('mysql').table('users').select().toRawSQL()
24+
);
25+
26+
expect(r.headers).toEqual(
27+
expect.arrayContaining([
28+
expect.objectContaining({ name: 'id' }),
29+
expect.objectContaining({ name: 'name' }),
30+
])
31+
);
32+
});

src/libs/ConnectionSettingTree.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { faFolder } from '@fortawesome/free-solid-svg-icons';
22
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
3-
import { ConnectionConfigTree } from 'drivers/SQLLikeConnection';
3+
import { ConnectionConfigTree } from 'drivers/base/SQLLikeConnection';
44
import Icon from 'renderer/components/Icon';
55
import { TreeViewItemData } from 'renderer/components/TreeView';
66

src/libs/ConnectionString.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
ConnectionStoreConfig,
33
ConnectionStoreItem,
4-
} from 'drivers/SQLLikeConnection';
4+
} from 'drivers/base/SQLLikeConnection';
55

66
export default class ConnectionString {
77
static decode(connectionString: string): ConnectionStoreConfig {

src/libs/SqlRunnerManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SqlQueryCallback } from 'drivers/SQLLikeConnection';
1+
import { SqlQueryCallback } from 'drivers/base/SQLLikeConnection';
22
import { QueryResult } from 'types/SqlResult';
33
import { SqlStatement } from 'types/SqlStatement';
44
import { Parser, AST } from 'node-sql-parser';

0 commit comments

Comments
 (0)