1
1
mirror of https://github.com/Fabio286/antares.git synced 2025-03-01 09:57:56 +01:00

perf(SQLite): improvements in field length detection

This commit is contained in:
Fabio Di Stasio 2021-11-18 19:43:08 +01:00
parent 3efeb45c46
commit 93b4a7063b
2 changed files with 20 additions and 7 deletions

View File

@ -101,7 +101,7 @@ module.exports = [
types: [ types: [
{ {
name: 'DATE', name: 'DATE',
length: true, length: false,
collation: false, collation: false,
unsigned: false, unsigned: false,
zerofill: false zerofill: false

View File

@ -2,7 +2,7 @@
import sqlite from 'better-sqlite3'; import sqlite from 'better-sqlite3';
import { AntaresCore } from '../AntaresCore'; import { AntaresCore } from '../AntaresCore';
import dataTypes from 'common/data-types/mysql'; import dataTypes from 'common/data-types/mysql';
import { NUMBER, FLOAT } from 'common/fieldTypes'; import { NUMBER, FLOAT, TIME, DATETIME } from 'common/fieldTypes';
export class SQLiteClient extends AntaresCore { export class SQLiteClient extends AntaresCore {
constructor (args) { constructor (args) {
@ -150,7 +150,7 @@ export class SQLiteClient extends AntaresCore {
return { return {
name: field.name, name: field.name,
key: null, key: null,
type, type: type.trim(),
schema: schema, schema: schema,
table: table, table: table,
numPrecision: [...NUMBER, ...FLOAT].includes(type) ? length : null, numPrecision: [...NUMBER, ...FLOAT].includes(type) ? length : null,
@ -730,9 +730,21 @@ export class SQLiteClient extends AntaresCore {
let remappedFields = fields let remappedFields = fields
? fields.map(field => { ? fields.map(field => {
const parsedType = field.type?.includes('(') let [parsedType, length] = field.type?.includes('(')
? field.type.split('(')[0] ? field.type.replace(')', '').split('(').map(el => {
: field.type; if (!isNaN(el))
el = +el;
else
el = el.trim();
return el;
})
: [field.type, null];
if ([...TIME, ...DATETIME].includes(parsedType)) {
const firstNotNull = queryResult.find(res => res[field.name] !== null);
if (firstNotNull[field.name].includes('.'))
length = firstNotNull[field.name].split('.').pop().length;
}
return { return {
name: field.name, name: field.name,
@ -742,7 +754,8 @@ 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 !== null ? parsedType : detectedTypes[field.name] type: field.type !== null ? parsedType : detectedTypes[field.name],
length
}; };
}).filter(Boolean) }).filter(Boolean)
: []; : [];