Removed knex

This commit is contained in:
Fabio 2020-06-07 14:38:38 +02:00
parent 268688cdb8
commit 4e508061fd
13 changed files with 421 additions and 362 deletions

516
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -31,11 +31,11 @@
"codemirror": "^5.54.0",
"electron-log": "^4.2.0",
"electron-updater": "^4.3.1",
"knex": "^0.21.1",
"lodash": "^4.17.15",
"material-design-icons": "^3.0.1",
"mssql": "^6.2.0",
"mysql": "^2.18.1",
"mysql2": "^2.1.0",
"pg": "^8.2.1",
"source-map-support": "^0.5.16",
"spectre.css": "^0.5.8",

View File

@ -1,29 +1,27 @@
import { ipcMain } from 'electron';
import knex from 'knex';
import { AntaresConnector } from '../libs/AntaresConnector';
import InformationSchema from '../models/InformationSchema';
import { RawQuery } from '../models/RawQuery';
import GenericQuery from '../models/GenericQuery';
const connections = {};
export default () => {
ipcMain.handle('testConnection', async (event, conn) => {
const connection = knex({
const Connection = new AntaresConnector({
client: conn.client,
connection: {
params: {
host: conn.host,
port: +conn.port,
user: conn.user,
password: conn.password
},
pool: {
min: 1,
max: 3
}
});
await Connection.connect();
try {
await InformationSchema.testConnection(connection);
await InformationSchema.testConnection(Connection);
return { status: 'success' };
}
@ -37,23 +35,22 @@ export default () => {
});
ipcMain.handle('connect', async (event, conn) => {
const connection = knex({
const Connection = new AntaresConnector({
client: conn.client,
connection: {
params: {
host: conn.host,
port: +conn.port,
user: conn.user,
password: conn.password
},
pool: {
min: 1,
max: 3
}
poolSize: 3
});
Connection.connect();
try {
const structure = await InformationSchema.getStructure(connection);
connections[conn.uid] = connection;
const { rows: structure } = await InformationSchema.getStructure(Connection);
connections[conn.uid] = Connection;
return { status: 'success', response: structure };
}
catch (err) {
@ -68,7 +65,7 @@ export default () => {
ipcMain.handle('refresh', async (event, uid) => {
try {
const structure = await InformationSchema.getStructure(connections[uid]);
const { rows: structure } = await InformationSchema.getStructure(connections[uid]);
return { status: 'success', response: structure };
}
catch (err) {
@ -76,15 +73,11 @@ export default () => {
}
});
ipcMain.on('runQuery', async (event, { connection, query, database }) => {
const knexIstance = connections[connection.uid];
const Query = new RawQuery({ knexIstance, database });
ipcMain.handle('rawQuery', async (event, { uid, query, database }) => {
if (!query) return;
try {
Query.runQuery(query);
Query.on('row', row => {
event.sender.send('row', row);
});
const result = await GenericQuery.raw(connections[uid], query, database);
return { status: 'success', response: result };
}
catch (err) {
return { status: 'error', response: err.toString() };

View File

@ -0,0 +1,54 @@
'use strict';
import mysql from 'mysql2';
export class AntaresConnector {
constructor (args) {
this.client = args.client;
this.params = args.params;
this.poolSize = args.poolSize || false;
this.connection = null;
}
connect () {
switch (this.client) {
case 'maria':
case 'mysql':
if (!this.poolSize) {
const connection = mysql.createConnection(this.params);
this.connection = connection.promise();
}
else {
const pool = mysql.createPool({ ...this.params, connectionLimit: this.poolSize });
this.connection = pool.promise();
}
break;
default:
break;
}
}
async raw (sql) {
switch (this.client) {
case 'maria':
case 'mysql': {
const [rows, fields] = await this.connection.query(sql);
return { rows, fields };
}
default:
break;
}
}
destroy () {
switch (this.client) {
case 'maria':
case 'mysql': {
this.connection.end();
break;
}
default:
break;
}
}
}

View File

@ -0,0 +1,7 @@
'use strict';
export default class {
static async raw (connection, query, database) {
if (database) await connection.raw(`USE \`${database}\``);
return connection.raw(query);
}
}

View File

@ -1,16 +1,10 @@
'use strict';
export default class {
static testConnection (connection) {
return connection('TABLES')
.select({ result: 1 })
.withSchema('information_schema');
return connection.raw('SELECT 1+1');
}
static getStructure (connection) {
return connection('TABLES')
.select('*')
.withSchema('information_schema')
.orderBy(['TABLE_SCHEMA', 'TABLE_NAME'], 'asc');
return connection.raw('SELECT * FROM information_schema.TABLES ORDER BY TABLE_SCHEMA, TABLE_NAME ASC');
}
}

View File

@ -1,22 +0,0 @@
'use strict';
import { EventEmitter } from 'events';
export class RawQuery extends EventEmitter {
constructor ({ knexIstance, database }) {
super();
this.conn = knexIstance;
this.database = database;
}
async runQuery (query) {
if (this.database) await this.conn.raw(`USE \`${this.database}\``);
const stream = this.conn.raw(query).stream();
stream.on('data', row => {
this.emit('row', row);
});
stream.on('error', err => {
this.emit('error', err);
});
}
}

View File

@ -12,17 +12,21 @@
</div>
</div>
<div ref="resultTable" class="workspace-query-results column col-12">
<table v-if="results.length" class="table table-hover">
<table v-if="results" class="table table-hover">
<thead>
<tr>
<th v-for="field in fields" :key="field">
{{ field }}
<th v-for="field in results.fields" :key="field.name">
{{ field.name }}
</th>
</tr>
</thead>
<tbody>
<tr v-for="(row, rKey) in results" :key="rKey">
<td v-for="(col, cKey) in row" :key="cKey">
<tr v-for="(row, rKey) in results.rows" :key="rKey">
<td
v-for="(col, cKey) in row"
:key="cKey"
:class="fieldType(col)"
>
{{ col }}
</td>
</tr>
@ -33,7 +37,7 @@
</template>
<script>
import { ipcRenderer } from 'electron';
import Connection from '@/ipc-api/Connection';
import QueryEditor from '@/components/QueryEditor';
import { mapGetters, mapActions } from 'vuex';
@ -48,7 +52,7 @@ export default {
data () {
return {
query: '',
results: []
results: {}
};
},
computed: {
@ -57,9 +61,6 @@ export default {
}),
workspace () {
return this.getWorkspace(this.connection.uid);
},
fields () {
return Object.keys(this.results[0]);
}
},
mounted () {
@ -73,21 +74,22 @@ export default {
addNotification: 'notifications/addNotification'
}),
async runQuery () {
this.results = [];
if (!this.query) return;
this.results = {};
this.resizeResults();
const params = {
connection: this.connection,
uid: this.connection.uid,
query: this.query,
database: this.workspace.breadcrumbs.database
};
try {
ipcRenderer.send('runQuery', params);
ipcRenderer.on('row', (event, row) => {
this.results.push(row);
});
const { status, response } = await Connection.rawQuery(params);
if (status === 'success')
this.results = response;
else
this.addNotification({ status: 'error', message: response });
}
catch (err) {
this.addNotification({ status: 'error', message: err.stack });
@ -101,6 +103,15 @@ export default {
const size = window.innerHeight - el.getBoundingClientRect().top - footer.offsetHeight;
el.style.height = size + 'px';
}
},
fieldType (col) {
let type = typeof col;
if (type === 'object')
if (col instanceof Date) type = 'date';
if (col instanceof Uint8Array) type = 'blob';
if (col === null) type = 'null';
return `type-${type}`;
}
}
};
@ -138,6 +149,30 @@ export default {
td{
border-color: $bg-color-light;
padding: 0 .4rem;
text-overflow: ellipsis;
max-width: 200px;
white-space: nowrap;
overflow: hidden;
&.type-string{
color: seagreen;
}
&.type-number{
color: cornflowerblue;
text-align: right;
}
&.type-date{
color: coral;
}
&.type-blob{
color: darkorchid;
}
&.type-null{
color: gray;
&::after{
content: 'NULL';
}
}
}
}
}

View File

@ -1 +1 @@
<svg height="32" viewBox="0 0 45.025 44.217" width="32" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><clipPath id="a"><path d="m0 0h191.356v57.344h-191.356z"/></clipPath><path clip-path="url(#a)" d="m75.198 5.328c-1.872.047-2.977.863-3.34 2.42.48.418 1.126.6 1.77.572 1.415-.06 2.817-1.138 2.42-2.965-.298-.025-.582-.035-.85-.027m9.642-5.328h-.167c-1.335.043-1.542.767-4.425 1.477-2.912.717-5.725.028-8.86 1.344-9.363 3.927-11.358 17.472-19.868 22.279-6.36 3.593-12.512 5.188-18.28 6.995-3.792 1.188-7.552 2.556-10.988 5.516-2.667 2.3-3.4 4.085-6.177 6.97-2.835 2.933-11.553-2.258-15.8 1.54a.84.84 0 0 0 .014 1.253c.92.805 2.67 2.722 4.336 3.314-.528 1-3.513 3.946-2.904 5.42.64 1.55 8.04.497 14.88-3.633 3.185-1.924 5.723-4.696 10.685-5.357 6.42-.855 13.817.55 21.25 1.62-1.103 3.286-3.315 5.473-5.088 8.1-.55.592 1.103.658 2.986.3 3.4-.838 5.832-1.513 8.4-3 3.143-1.83 3.62-6.52 7.474-7.534 1.864 2.865 6.5 3.83 10.074 2.3.198-.084.392-.177.582-.275.43-.375.178-.813-.086-1.135a6.21 6.21 0 0 1 -.362-.364c-2.012-2.162-2.472-7.266-1.58-9.748 1.017-2.824 2.022-7.343 3.046-11.075 1.1-4 1.506-9.063 2.837-11.106 2.002-3.072 4.215-4.127 6.136-5.86s3.68-3.42 3.62-7.384c-.028-1.223-.629-1.927-1.735-1.957m.204 4.163c-.397 2.734-2.144 4.237-4.208 5.687-1.8 1.27-3.794 2.493-5.07 4.477-1.305 2.03-2.134 8.985-4.16 15.852-1.68 5.698-4.184 11.335-8.467 14.05-.278.176-.645.015-.704-.3-.3-1.592-.24-4.5-.734-3.56-.62 1.77-1.322 3.458-2.143 5.027-2.52 4.816-6.166 8.505-12.057 9.95a.53.53 0 0 1 -.552-.82c2.718-3.77 5.15-7.825 5.447-14.014.025-.534-.646-.778-.983-.364-1.284 1.583-1.6 5.347-3.477 6.506-1.474.16-2.967.16-4.47.07-6.17-.37-12.502-2.226-18.274-.373-3.93 1.262-8.057 4.85-11.386 6.293-3.912 1.686-5.766 3.286-10.706 3.176-.505-.68 2.062-3.623 2.934-4.893.278-.407-.317-.835-.874-1.1-1.338-.614-2.68-2.28-4.107-2.93.183-.337.83-.674 1.187-.88 3.24-1.88 11.832 2.124 14.14-.143 1.425-1.398 2.385-2.626 3.353-4.05.94-1.38 2.368-2.838 3.847-4.047a31.3 31.3 0 0 1 1.94-1.435c2.52-1.724 3.907-1.852 7.17-3.064 4.152-1.544 9.293-2.898 13.747-4.6 2.752-1.053 5.744-2.35 8.183-4.17.58-.432 1.127-.893 1.634-1.386 6.964-6.8 8.345-18.766 19.2-19.882 1.314-.135 2.248-.192 3.228-.223 1.096-.03 2.18-.3 3.263-.818.334-.146 2.324-1.35 2.996-.768.448.388.115 2.492.086 2.72" fill="#444b5e" transform="matrix(.52012 0 0 .52012 0 7.19564)"/></svg>
<svg height="32" viewBox="0 0 45.025 44.217" width="32" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><clipPath id="a"><path d="m0 0h191.356v57.344h-191.356z"/></clipPath><path clip-path="url(#a)" d="m75.198 5.328c-1.872.047-2.977.863-3.34 2.42.48.418 1.126.6 1.77.572 1.415-.06 2.817-1.138 2.42-2.965-.298-.025-.582-.035-.85-.027m9.642-5.328h-.167c-1.335.043-1.542.767-4.425 1.477-2.912.717-5.725.028-8.86 1.344-9.363 3.927-11.358 17.472-19.868 22.279-6.36 3.593-12.512 5.188-18.28 6.995-3.792 1.188-7.552 2.556-10.988 5.516-2.667 2.3-3.4 4.085-6.177 6.97-2.835 2.933-11.553-2.258-15.8 1.54a.84.84 0 0 0 .014 1.253c.92.805 2.67 2.722 4.336 3.314-.528 1-3.513 3.946-2.904 5.42.64 1.55 8.04.497 14.88-3.633 3.185-1.924 5.723-4.696 10.685-5.357 6.42-.855 13.817.55 21.25 1.62-1.103 3.286-3.315 5.473-5.088 8.1-.55.592 1.103.658 2.986.3 3.4-.838 5.832-1.513 8.4-3 3.143-1.83 3.62-6.52 7.474-7.534 1.864 2.865 6.5 3.83 10.074 2.3.198-.084.392-.177.582-.275.43-.375.178-.813-.086-1.135a6.21 6.21 0 0 1 -.362-.364c-2.012-2.162-2.472-7.266-1.58-9.748 1.017-2.824 2.022-7.343 3.046-11.075 1.1-4 1.506-9.063 2.837-11.106 2.002-3.072 4.215-4.127 6.136-5.86s3.68-3.42 3.62-7.384c-.028-1.223-.629-1.927-1.735-1.957m.204 4.163c-.397 2.734-2.144 4.237-4.208 5.687-1.8 1.27-3.794 2.493-5.07 4.477-1.305 2.03-2.134 8.985-4.16 15.852-1.68 5.698-4.184 11.335-8.467 14.05-.278.176-.645.015-.704-.3-.3-1.592-.24-4.5-.734-3.56-.62 1.77-1.322 3.458-2.143 5.027-2.52 4.816-6.166 8.505-12.057 9.95a.53.53 0 0 1 -.552-.82c2.718-3.77 5.15-7.825 5.447-14.014.025-.534-.646-.778-.983-.364-1.284 1.583-1.6 5.347-3.477 6.506-1.474.16-2.967.16-4.47.07-6.17-.37-12.502-2.226-18.274-.373-3.93 1.262-8.057 4.85-11.386 6.293-3.912 1.686-5.766 3.286-10.706 3.176-.505-.68 2.062-3.623 2.934-4.893.278-.407-.317-.835-.874-1.1-1.338-.614-2.68-2.28-4.107-2.93.183-.337.83-.674 1.187-.88 3.24-1.88 11.832 2.124 14.14-.143 1.425-1.398 2.385-2.626 3.353-4.05.94-1.38 2.368-2.838 3.847-4.047a31.3 31.3 0 0 1 1.94-1.435c2.52-1.724 3.907-1.852 7.17-3.064 4.152-1.544 9.293-2.898 13.747-4.6 2.752-1.053 5.744-2.35 8.183-4.17.58-.432 1.127-.893 1.634-1.386 6.964-6.8 8.345-18.766 19.2-19.882 1.314-.135 2.248-.192 3.228-.223 1.096-.03 2.18-.3 3.263-.818.334-.146 2.324-1.35 2.996-.768.448.388.115 2.492.086 2.72" fill="#fff" transform="matrix(.52012 0 0 .52012 0 7.19564)"/></svg>

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@ -21,4 +21,8 @@ export default class {
static refresh (uid) {
return ipcRenderer.invoke('refresh', uid);
}
static rawQuery (params) {
return ipcRenderer.invoke('rawQuery', params);
}
}

View File

@ -0,0 +1,26 @@
.dbi{
display: inline-block;
width: 42px;
height: 42px;
background-size: cover;
&.dbi-mysql{
background-image: url('../images/svg/mysql.svg');
}
&.dbi-maria{
background-image: url('../images/svg/mariadb.svg');
}
&.dbi-mssql{
background-image: url('../images/svg/mssql.svg');
}
&.dbi-pg{
background-image: url('../images/svg/pg.svg');
}
&.dbi-oracledb{
background-image: url('../images/svg/oracledb.svg');
}
}

View File

@ -1,6 +1,7 @@
@import "variables";
@import "transitions";
@import "mdi-additions";
@import "db-icons";
@import "~spectre.css/src/spectre";
body{
@ -27,29 +28,6 @@ body{
align-items: center;
}
.dbi{
display: inline-block;
width: 42px;
height: 42px;
background-size: cover;
&.dbi-mysql{
background-image: url('../images/svg/mysql.svg');
}
&.dbi-mssql{
background-image: url('../images/svg/mssql.svg');
}
&.dbi-pg{
background-image: url('../images/svg/pg.svg');
}
&.dbi-oracledb{
background-image: url('../images/svg/oracledb.svg');
}
}
// Scrollbars
::-webkit-scrollbar {
width: 10px;

View File

@ -3,7 +3,7 @@ export default {
namespaced: true,
strict: true,
state: {
app_name: 'Antares - SQL Client',
app_name: 'Antares - Database Client',
app_version: process.env.PACKAGE_VERSION || 0,
is_loading: false,
is_new_modal: false,