mirror of
https://github.com/Fabio286/antares.git
synced 2025-06-05 21:59:22 +02:00
perf(SQLite): improvements in data visualization
This commit is contained in:
@ -37,6 +37,9 @@ module.exports = {
|
|||||||
databaseEdit: false,
|
databaseEdit: false,
|
||||||
schemaEdit: false,
|
schemaEdit: false,
|
||||||
tableSettings: false,
|
tableSettings: false,
|
||||||
|
tableOptions: false,
|
||||||
|
tableArray: false,
|
||||||
|
tableRealCount: false,
|
||||||
viewSettings: false,
|
viewSettings: false,
|
||||||
triggerSettings: false,
|
triggerSettings: false,
|
||||||
triggerFunctionSettings: false,
|
triggerFunctionSettings: false,
|
||||||
@ -49,13 +52,11 @@ module.exports = {
|
|||||||
unsigned: false,
|
unsigned: false,
|
||||||
nullable: false,
|
nullable: false,
|
||||||
zerofill: false,
|
zerofill: false,
|
||||||
tableOptions: false,
|
|
||||||
autoIncrement: false,
|
autoIncrement: false,
|
||||||
comment: false,
|
comment: false,
|
||||||
collation: false,
|
collation: false,
|
||||||
definer: false,
|
definer: false,
|
||||||
onUpdate: false,
|
onUpdate: false,
|
||||||
tableArray: false,
|
|
||||||
viewAlgorithm: false,
|
viewAlgorithm: false,
|
||||||
viewSqlSecurity: false,
|
viewSqlSecurity: false,
|
||||||
viewUpdateOption: false,
|
viewUpdateOption: false,
|
||||||
|
@ -35,6 +35,8 @@ module.exports = {
|
|||||||
databaseEdit: false,
|
databaseEdit: false,
|
||||||
schemaEdit: false,
|
schemaEdit: false,
|
||||||
tableSettings: false,
|
tableSettings: false,
|
||||||
|
tableArray: false,
|
||||||
|
tableRealCount: true,
|
||||||
viewSettings: false,
|
viewSettings: false,
|
||||||
triggerSettings: false,
|
triggerSettings: false,
|
||||||
triggerFunctionSettings: false,
|
triggerFunctionSettings: false,
|
||||||
@ -53,7 +55,6 @@ module.exports = {
|
|||||||
collation: false,
|
collation: false,
|
||||||
definer: false,
|
definer: false,
|
||||||
onUpdate: false,
|
onUpdate: false,
|
||||||
tableArray: false,
|
|
||||||
viewAlgorithm: false,
|
viewAlgorithm: false,
|
||||||
viewSqlSecurity: false,
|
viewSqlSecurity: false,
|
||||||
viewUpdateOption: false,
|
viewUpdateOption: false,
|
||||||
|
@ -54,7 +54,7 @@ export class SQLiteClient extends AntaresCore {
|
|||||||
for (const db of filteredDatabases) {
|
for (const db of filteredDatabases) {
|
||||||
if (!schemas.has(db.name)) continue;
|
if (!schemas.has(db.name)) continue;
|
||||||
|
|
||||||
let { rows: tables } = await this.raw(`SELECT * FROM "${db.name}".sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%';`);
|
let { rows: tables } = await this.raw(`SELECT * FROM "${db.name}".sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%' ORDER BY name`);
|
||||||
if (tables.length) {
|
if (tables.length) {
|
||||||
tables = tables.map(table => {
|
tables = tables.map(table => {
|
||||||
table.Db = db.name;
|
table.Db = db.name;
|
||||||
@ -77,17 +77,7 @@ export class SQLiteClient extends AntaresCore {
|
|||||||
if (schemas.has(db.name)) {
|
if (schemas.has(db.name)) {
|
||||||
// TABLES
|
// TABLES
|
||||||
const remappedTables = tablesArr.filter(table => table.Db === db.name).map(table => {
|
const remappedTables = tablesArr.filter(table => table.Db === db.name).map(table => {
|
||||||
let tableType;
|
const tableSize = 0;
|
||||||
switch (table.Comment) {
|
|
||||||
case 'VIEW':
|
|
||||||
tableType = 'view';
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
tableType = 'table';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
const tableSize = table.Data_length + table.Index_length;
|
|
||||||
schemaSize += tableSize;
|
schemaSize += tableSize;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -246,7 +236,7 @@ export class SQLiteClient extends AntaresCore {
|
|||||||
* @memberof SQLiteClient
|
* @memberof SQLiteClient
|
||||||
*/
|
*/
|
||||||
async getTableApproximateCount ({ schema, table }) {
|
async getTableApproximateCount ({ schema, table }) {
|
||||||
const { rows } = await this.raw(`SELECT table_rows "count" FROM information_schema.tables WHERE table_name = "${table}" AND table_schema = "${schema}"`);
|
const { rows } = await this.raw(`SELECT COUNT(*) AS count FROM "${schema}"."${table}"`);
|
||||||
|
|
||||||
return rows.length ? rows[0].count : 0;
|
return rows.length ? rows[0].count : 0;
|
||||||
}
|
}
|
||||||
@ -1182,10 +1172,12 @@ export class SQLiteClient extends AntaresCore {
|
|||||||
else if (Object.keys(this._query.insert).length)
|
else if (Object.keys(this._query.insert).length)
|
||||||
fromRaw = 'INTO';
|
fromRaw = 'INTO';
|
||||||
|
|
||||||
fromRaw += this._query.from ? ` ${this._query.schema ? `\`${this._query.schema}\`.` : ''}\`${this._query.from}\` ` : '';
|
fromRaw += this._query.from ? ` ${this._query.schema ? `"${this._query.schema}".` : ''}"${this._query.from}" ` : '';
|
||||||
|
|
||||||
// WHERE
|
// WHERE
|
||||||
const whereArray = this._query.where.reduce(this._reducer, []);
|
const whereArray = this._query.where
|
||||||
|
.reduce(this._reducer, [])
|
||||||
|
?.map(clausole => clausole.replace('= null', 'IS NULL'));
|
||||||
const whereRaw = whereArray.length ? `WHERE ${whereArray.join(' AND ')} ` : '';
|
const whereRaw = whereArray.length ? `WHERE ${whereArray.join(' AND ')} ` : '';
|
||||||
|
|
||||||
// UPDATE
|
// UPDATE
|
||||||
@ -1258,9 +1250,26 @@ export class SQLiteClient extends AntaresCore {
|
|||||||
const keysArr = [];
|
const keysArr = [];
|
||||||
|
|
||||||
const { rows, report, fields, keys, duration } = await new Promise((resolve, reject) => {
|
const { rows, report, fields, keys, duration } = await new Promise((resolve, reject) => {
|
||||||
|
let queryResult;
|
||||||
|
let affectedRows;
|
||||||
|
let fields;
|
||||||
|
const detectedTypes = {};
|
||||||
|
|
||||||
const stmt = connection.prepare(query);
|
const stmt = connection.prepare(query);
|
||||||
const queryResult = stmt.all();
|
if (stmt.reader) {
|
||||||
const fields = stmt.columns();
|
queryResult = stmt.all();
|
||||||
|
fields = stmt.columns();
|
||||||
|
|
||||||
|
if (queryResult.length) {
|
||||||
|
fields.forEach(field => {
|
||||||
|
detectedTypes[field.name] = typeof queryResult[0][field.name];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const info = queryResult = stmt.run();
|
||||||
|
affectedRows = info.changes;
|
||||||
|
}
|
||||||
|
|
||||||
const remappedFields = fields
|
const remappedFields = fields
|
||||||
? fields.map(field => {
|
? fields.map(field => {
|
||||||
@ -1272,7 +1281,7 @@ export class SQLiteClient extends AntaresCore {
|
|||||||
table: field.table,
|
table: field.table,
|
||||||
tableAlias: field.table,
|
tableAlias: field.table,
|
||||||
orgTable: field.table,
|
orgTable: field.table,
|
||||||
type: field.type
|
type: field.type !== null ? field.type : detectedTypes[field.name]
|
||||||
};
|
};
|
||||||
}).filter(Boolean)
|
}).filter(Boolean)
|
||||||
: [];
|
: [];
|
||||||
@ -1282,7 +1291,7 @@ export class SQLiteClient extends AntaresCore {
|
|||||||
resolve({
|
resolve({
|
||||||
duration: timeStop - timeStart,
|
duration: timeStop - timeStart,
|
||||||
rows: Array.isArray(queryResult) ? queryResult.some(el => Array.isArray(el)) ? [] : queryResult : false,
|
rows: Array.isArray(queryResult) ? queryResult.some(el => Array.isArray(el)) ? [] : queryResult : false,
|
||||||
report: !Array.isArray(queryResult) ? queryResult : false,
|
report: affectedRows !== undefined ? { affectedRows } : null,
|
||||||
fields: remappedFields,
|
fields: remappedFields,
|
||||||
keys: keysArr
|
keys: keysArr
|
||||||
});
|
});
|
||||||
|
@ -43,7 +43,7 @@
|
|||||||
<span v-html="highlightWord(table.name)" />
|
<span v-html="highlightWord(table.name)" />
|
||||||
</a>
|
</a>
|
||||||
<div
|
<div
|
||||||
v-if="table.type === 'table'"
|
v-if="table.type === 'table' && table.size !== false"
|
||||||
class="table-size tooltip tooltip-left mr-1"
|
class="table-size tooltip tooltip-left mr-1"
|
||||||
:data-tooltip="formatBytes(table.size)"
|
:data-tooltip="formatBytes(table.size)"
|
||||||
>
|
>
|
||||||
|
@ -93,7 +93,7 @@
|
|||||||
<div v-if="resultsCount">
|
<div v-if="resultsCount">
|
||||||
{{ $t('word.results') }}: <b>{{ resultsCount.toLocaleString() }}</b>
|
{{ $t('word.results') }}: <b>{{ resultsCount.toLocaleString() }}</b>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="affectedCount">
|
<div v-if="affectedCount !== null">
|
||||||
{{ $t('message.affectedRows') }}: <b>{{ affectedCount }}</b>
|
{{ $t('message.affectedRows') }}: <b>{{ affectedCount }}</b>
|
||||||
</div>
|
</div>
|
||||||
<div class="input-group" :title="$t('word.schema')">
|
<div class="input-group" :title="$t('word.schema')">
|
||||||
@ -170,7 +170,7 @@ export default {
|
|||||||
selectedSchema: null,
|
selectedSchema: null,
|
||||||
resultsCount: 0,
|
resultsCount: 0,
|
||||||
durationsCount: 0,
|
durationsCount: 0,
|
||||||
affectedCount: 0,
|
affectedCount: null,
|
||||||
editorHeight: 200,
|
editorHeight: 200,
|
||||||
isHistoryOpen: false
|
isHistoryOpen: false
|
||||||
};
|
};
|
||||||
@ -255,9 +255,14 @@ export default {
|
|||||||
|
|
||||||
if (status === 'success') {
|
if (status === 'success') {
|
||||||
this.results = Array.isArray(response) ? response : [response];
|
this.results = Array.isArray(response) ? response : [response];
|
||||||
this.resultsCount += this.results.reduce((acc, curr) => acc + (curr.rows ? curr.rows.length : 0), 0);
|
this.resultsCount = this.results.reduce((acc, curr) => acc + (curr.rows ? curr.rows.length : 0), 0);
|
||||||
this.durationsCount += this.results.reduce((acc, curr) => acc + curr.duration, 0);
|
this.durationsCount = this.results.reduce((acc, curr) => acc + curr.duration, 0);
|
||||||
this.affectedCount += this.results.reduce((acc, curr) => acc + (curr.report ? curr.report.affectedRows : 0), 0);
|
this.affectedCount = this.results
|
||||||
|
.filter(result => result.report !== null)
|
||||||
|
.reduce((acc, curr) => {
|
||||||
|
if (acc === null) acc = 0;
|
||||||
|
return acc + (curr.report ? curr.report.affectedRows : 0);
|
||||||
|
}, null);
|
||||||
|
|
||||||
this.updateTabContent({
|
this.updateTabContent({
|
||||||
uid: this.connection.uid,
|
uid: this.connection.uid,
|
||||||
@ -285,7 +290,7 @@ export default {
|
|||||||
this.results = [];
|
this.results = [];
|
||||||
this.resultsCount = 0;
|
this.resultsCount = 0;
|
||||||
this.durationsCount = 0;
|
this.durationsCount = 0;
|
||||||
this.affectedCount = 0;
|
this.affectedCount = null;
|
||||||
},
|
},
|
||||||
resize (e) {
|
resize (e) {
|
||||||
const el = this.$refs.queryEditor.$el;
|
const el = this.$refs.queryEditor.$el;
|
||||||
|
@ -120,7 +120,12 @@
|
|||||||
{{ $t('word.results') }}: <b>{{ results[0].rows.length | localeString }}</b>
|
{{ $t('word.results') }}: <b>{{ results[0].rows.length | localeString }}</b>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="hasApproximately || (page > 1 && approximateCount)">
|
<div v-if="hasApproximately || (page > 1 && approximateCount)">
|
||||||
{{ $t('word.total') }}: <b :title="$t('word.approximately')">≈ {{ approximateCount | localeString }}</b>
|
{{ $t('word.total') }}: <b
|
||||||
|
:title="!customizations.tableRealCount ? $t('word.approximately') : ''"
|
||||||
|
>
|
||||||
|
<span v-if="!customizations.tableRealCount">≈</span>
|
||||||
|
{{ approximateCount | localeString }}
|
||||||
|
</b>
|
||||||
</div>
|
</div>
|
||||||
<div class="d-flex" :title="$t('word.schema')">
|
<div class="d-flex" :title="$t('word.schema')">
|
||||||
<i class="mdi mdi-18px mdi-database mr-1" /><b>{{ schema }}</b>
|
<i class="mdi mdi-18px mdi-database mr-1" /><b>{{ schema }}</b>
|
||||||
@ -231,6 +236,9 @@ export default {
|
|||||||
workspace () {
|
workspace () {
|
||||||
return this.getWorkspace(this.connection.uid);
|
return this.getWorkspace(this.connection.uid);
|
||||||
},
|
},
|
||||||
|
customizations () {
|
||||||
|
return this.workspace.customizations;
|
||||||
|
},
|
||||||
isTable () {
|
isTable () {
|
||||||
return !!this.workspace.breadcrumbs.table;
|
return !!this.workspace.breadcrumbs.table;
|
||||||
},
|
},
|
||||||
|
@ -17,10 +17,12 @@
|
|||||||
(
|
(
|
||||||
"char": $string-color,
|
"char": $string-color,
|
||||||
"varchar": $string-color,
|
"varchar": $string-color,
|
||||||
|
"longvarchar": $string-color,
|
||||||
"text": $string-color,
|
"text": $string-color,
|
||||||
"tinytext": $string-color,
|
"tinytext": $string-color,
|
||||||
"mediumtext": $string-color,
|
"mediumtext": $string-color,
|
||||||
"longtext": $string-color,
|
"longtext": $string-color,
|
||||||
|
"string": $string-color,
|
||||||
"json": $string-color,
|
"json": $string-color,
|
||||||
"name": $string-color,
|
"name": $string-color,
|
||||||
"character": $string-color,
|
"character": $string-color,
|
||||||
@ -50,6 +52,7 @@
|
|||||||
"oid": $number-color,
|
"oid": $number-color,
|
||||||
"xid": $number-color,
|
"xid": $number-color,
|
||||||
"money": $number-color,
|
"money": $number-color,
|
||||||
|
"number": $number-color,
|
||||||
"datetime": $date-color,
|
"datetime": $date-color,
|
||||||
"date": $date-color,
|
"date": $date-color,
|
||||||
"time": $date-color,
|
"time": $date-color,
|
||||||
|
@ -412,6 +412,11 @@ export default {
|
|||||||
indexTypes = require('common/index-types/postgresql');
|
indexTypes = require('common/index-types/postgresql');
|
||||||
customizations = require('common/customizations/postgresql');
|
customizations = require('common/customizations/postgresql');
|
||||||
break;
|
break;
|
||||||
|
case 'sqlite':
|
||||||
|
// dataTypes = require('common/data-types/sqlite');
|
||||||
|
// indexTypes = require('common/index-types/sqlite');
|
||||||
|
customizations = require('common/customizations/sqlite');
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { status, response: version } = await Schema.getVersion(connection.uid);
|
const { status, response: version } = await Schema.getVersion(connection.uid);
|
||||||
|
Reference in New Issue
Block a user