Browse Source

feat: tree-shaking lodash in sqlClients

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/3668/head
mertmit 2 years ago
parent
commit
24a8f25d5d
  1. 25
      packages/nocodb/src/lib/db/sql-client/lib/KnexClient.ts
  2. 4
      packages/nocodb/src/lib/db/sql-client/lib/mssql/MssqlClient.ts
  3. 32
      packages/nocodb/src/lib/db/sql-client/lib/mysql/MysqlClient.ts
  4. 38
      packages/nocodb/src/lib/db/sql-client/lib/oracle/OracleClient.ts
  5. 11
      packages/nocodb/src/lib/db/sql-client/lib/pg/PgClient.ts
  6. 17
      packages/nocodb/src/lib/db/sql-client/lib/sqlite/SqliteClient.ts

25
packages/nocodb/src/lib/db/sql-client/lib/KnexClient.ts

@ -5,7 +5,8 @@ import Debug from '../../util/Debug';
import Emit from '../../util/emit';
import Result from '../../util/Result';
import lodash from 'lodash';
import findIndex from 'lodash/findIndex';
import find from 'lodash/find';
import fs from 'fs';
import { promisify } from 'util';
import jsonfile from 'jsonfile';
@ -685,7 +686,7 @@ class KnexClient extends SqlClient {
}
_isColumnForeignKey(tableObj, cn) {
if (lodash.findIndex(tableObj.foreignKeys, { cn: cn }) === -1) {
if (findIndex(tableObj.foreignKeys, { cn: cn }) === -1) {
return false;
}
return true;
@ -699,7 +700,7 @@ class KnexClient extends SqlClient {
) {
if (tableObj.primaryKeys.length > 1) {
if (
lodash.findIndex(tableObj.primaryKeys, {
findIndex(tableObj.primaryKeys, {
cn: columnObj.cn,
}) > 0
) {
@ -763,7 +764,7 @@ class KnexClient extends SqlClient {
if (tableObj.primaryKeys.length) {
const dt = this.getKnexDataTypeMock(pk.ct);
const col = lodash.find(tableObj.columns, {
const col = find(tableObj.columns, {
cn: pk.cn,
});
@ -778,7 +779,7 @@ class KnexClient extends SqlClient {
let max1 = 10000;
let searchFrom = 0;
let foundIndex = lodash.findIndex(
let foundIndex = findIndex(
tableObj.columns,
{ ck: 'UNI' },
searchFrom
@ -798,7 +799,7 @@ class KnexClient extends SqlClient {
}
searchFrom = foundIndex;
foundIndex = lodash.findIndex(
foundIndex = findIndex(
tableObj.columns,
{ ck: 'UNI' },
searchFrom + 1
@ -807,7 +808,7 @@ class KnexClient extends SqlClient {
let max2 = 10000;
searchFrom = 0;
foundIndex = lodash.findIndex(tableObj.columns, { ck: 'MUL' }, searchFrom);
foundIndex = findIndex(tableObj.columns, { ck: 'MUL' }, searchFrom);
while (foundIndex !== -1) {
const col = tableObj.columns[foundIndex];
@ -823,7 +824,7 @@ class KnexClient extends SqlClient {
}
searchFrom = foundIndex;
foundIndex = lodash.findIndex(
foundIndex = findIndex(
tableObj.columns,
{ ck: 'MUL' },
searchFrom + 1
@ -1895,7 +1896,7 @@ class KnexClient extends SqlClient {
// let downQuery = "";
//
// for (let i = 0; i < args.columns.length; ++i) {
// const oldColumn = lodash.find(originalColumns, {
// const oldColumn = find(originalColumns, {
// cn: args.columns[i].cno
// });
//
@ -2046,7 +2047,7 @@ class KnexClient extends SqlClient {
pkUpdate(table, args.columns, args.originalColumns);
} else {
for (let i = 0; i < args.columns.length; ++i) {
const column = lodash.find(originalColumns, {
const column = find(originalColumns, {
cn: args.columns[i].cno,
});
@ -2090,7 +2091,7 @@ class KnexClient extends SqlClient {
pkUpdate(table, args.columns, args.originalColumns);
} else {
for (let i = 0; i < args.columns.length; ++i) {
const column = lodash.find(originalColumns, {
const column = find(originalColumns, {
cn: args.columns[i].cno,
});
if (args.columns[i].altered & 8) {
@ -2124,7 +2125,7 @@ class KnexClient extends SqlClient {
pkUpdate(table, args.columns, args.originalColumns);
} else {
for (let i = 0; i < args.columns.length; ++i) {
const column = lodash.find(originalColumns, {
const column = find(originalColumns, {
cn: args.columns[i].cno,
});
if (args.columns[i].altered & 8) {

4
packages/nocodb/src/lib/db/sql-client/lib/mssql/MssqlClient.ts

@ -4,7 +4,7 @@ import knex from 'knex';
import KnexClient from '../KnexClient';
import Debug from '../../../util/Debug';
import Result from '../../../util/Result';
import lodash from 'lodash';
import find from 'lodash/find';
const log = new Debug('MssqlClient');
@ -1964,7 +1964,7 @@ class MssqlClient extends KnexClient {
let downQuery = '';
for (let i = 0; i < args.columns.length; ++i) {
const oldColumn = lodash.find(originalColumns, {
const oldColumn = find(originalColumns, {
cn: args.columns[i].cno,
});

32
packages/nocodb/src/lib/db/sql-client/lib/mysql/MysqlClient.ts

@ -1,6 +1,8 @@
import knex from 'knex';
import lodash from 'lodash';
import isEmpty from 'lodash/isEmpty';
import mapKeys from 'lodash/mapKeys';
import find from 'lodash/find';
import Debug from '../../../util/Debug';
import Emit from '../../../util/emit';
import Result from '../../../util/Result';
@ -551,7 +553,7 @@ class MysqlClient extends KnexClient {
);
if (response.length === 2) {
result.data.list = response[0].map((v) =>
lodash.mapKeys(v, (_, k) => k.toLowerCase())
mapKeys(v, (_, k) => k.toLowerCase())
);
} else {
log.debug('Unknown response for schemaList:', result.data.list.length);
@ -620,7 +622,7 @@ class MysqlClient extends KnexClient {
for (let i = 0; i < response[0].length; ++i) {
const column: any = {};
response[0][i] = lodash.mapKeys(response[0][i], (_v, k) =>
response[0][i] = mapKeys(response[0][i], (_v, k) =>
k.toLowerCase()
);
@ -753,7 +755,7 @@ class MysqlClient extends KnexClient {
for (let i = 0; i < response[0].length; ++i) {
let index = response[0][i];
index = lodash.mapKeys(index, function (_v, k) {
index = mapKeys(index, function (_v, k) {
return k.toLowerCase();
});
index.cn = index.column_name;
@ -810,7 +812,7 @@ class MysqlClient extends KnexClient {
for (let i = 0; i < response[0].length; ++i) {
let index = response[0][i];
index = lodash.mapKeys(index, function (_v, k) {
index = mapKeys(index, function (_v, k) {
return k.toLowerCase();
});
indexes.push(index);
@ -868,7 +870,7 @@ class MysqlClient extends KnexClient {
for (let i = 0; i < response[0].length; ++i) {
let relation = response[0][i];
relation = lodash.mapKeys(relation, function (_v, k) {
relation = mapKeys(relation, function (_v, k) {
return k.toLowerCase();
});
relations.push(relation);
@ -923,7 +925,7 @@ class MysqlClient extends KnexClient {
for (let i = 0; i < response[0].length; ++i) {
let relation = response[0][i];
relation = lodash.mapKeys(relation, function (_v, k) {
relation = mapKeys(relation, function (_v, k) {
return k.toLowerCase();
});
relations.push(relation);
@ -985,7 +987,7 @@ class MysqlClient extends KnexClient {
for (let i = 0; i < response[0].length; ++i) {
let trigger = response[0][i];
trigger = lodash.mapKeys(trigger, function (_v, k) {
trigger = mapKeys(trigger, function (_v, k) {
return k.toLowerCase();
});
trigger.trigger_name = trigger.trigger;
@ -1040,7 +1042,7 @@ class MysqlClient extends KnexClient {
for (let i = 0; i < response[0].length; ++i) {
let fn = response[0][i];
fn = lodash.mapKeys(fn, function (_v, k) {
fn = mapKeys(fn, function (_v, k) {
return k.toLowerCase();
});
fn.function_name = fn.name;
@ -1099,7 +1101,7 @@ class MysqlClient extends KnexClient {
for (let i = 0; i < response[0].length; ++i) {
let procedure = response[0][i];
procedure = lodash.mapKeys(procedure, function (_v, k) {
procedure = mapKeys(procedure, function (_v, k) {
return k.toLowerCase();
});
procedure.procedure_name = procedure.name;
@ -1205,7 +1207,7 @@ class MysqlClient extends KnexClient {
for (let i = 0; i < response[0].length; ++i) {
let _function = response[0][i];
_function = lodash.mapKeys(_function, function (_v, k) {
_function = mapKeys(_function, function (_v, k) {
return k.toLowerCase();
});
@ -1259,7 +1261,7 @@ class MysqlClient extends KnexClient {
for (let i = 0; i < response[0].length; ++i) {
let procedure = response[0][i];
procedure = lodash.mapKeys(procedure, function (_v, k) {
procedure = mapKeys(procedure, function (_v, k) {
return k.toLowerCase();
});
@ -1311,7 +1313,7 @@ class MysqlClient extends KnexClient {
for (let i = 0; i < response[0].length; ++i) {
let view = response[0][i];
view = lodash.mapKeys(view, function (_v, k) {
view = mapKeys(view, function (_v, k) {
return k.toLowerCase();
});
@ -1847,7 +1849,7 @@ class MysqlClient extends KnexClient {
*/
async _getQuery(args) {
try {
if (lodash.isEmpty(this._version)) {
if (isEmpty(this._version)) {
const result = await this.version();
this._version = result.data.object;
log.debug(
@ -2085,7 +2087,7 @@ class MysqlClient extends KnexClient {
let downQuery = '';
for (let i = 0; i < args.columns.length; ++i) {
const oldColumn = lodash.find(originalColumns, {
const oldColumn = find(originalColumns, {
cn: args.columns[i].cno,
});

38
packages/nocodb/src/lib/db/sql-client/lib/oracle/OracleClient.ts

@ -1,9 +1,9 @@
import knex from 'knex';
import _ from 'lodash';
import KnexClient from '../KnexClient';
import Debug from '../../../util/Debug';
import Result from '../../../util/Result';
import lodash from 'lodash';
import mapKeys from 'lodash/mapKeys';
import find from 'lodash/find';
const log = new Debug('OracleClient');
@ -127,7 +127,7 @@ class OracleClient extends KnexClient {
result.data.object = {};
let versionDetails = rows[0];
versionDetails = _.mapKeys(versionDetails, (_v, k) => k.toLowerCase());
versionDetails = mapKeys(versionDetails, (_v, k) => k.toLowerCase());
const version = versionDetails.version.split('.');
result.data.object.version = versionDetails.version;
result.data.object.primary = version[0];
@ -399,7 +399,7 @@ class OracleClient extends KnexClient {
);
for (let i = 0; i < rows.length; i++) {
let el = rows[i];
el = _.mapKeys(el, (_v, k) => k.toLowerCase());
el = mapKeys(el, (_v, k) => k.toLowerCase());
rows[i] = el;
}
@ -431,7 +431,7 @@ class OracleClient extends KnexClient {
);
for (let i = 0; i < rows.length; i++) {
let el = rows[i];
el = _.mapKeys(el, (_v, k) => k.toLowerCase());
el = mapKeys(el, (_v, k) => k.toLowerCase());
rows[i] = el;
}
@ -567,7 +567,7 @@ class OracleClient extends KnexClient {
for (let i = 0; i < response.length; i++) {
let el = response[i];
el = _.mapKeys(el, (_v, k) => k.toLowerCase());
el = mapKeys(el, (_v, k) => k.toLowerCase());
el.np = el.data_precision;
el.pk = el.ck === 'P';
el.nrqd = el.nrqd === 'Y';
@ -639,7 +639,7 @@ class OracleClient extends KnexClient {
for (let i = 0; i < response.length; i++) {
let el = response[i];
el = _.mapKeys(el, (_v, k) => k.toLowerCase());
el = mapKeys(el, (_v, k) => k.toLowerCase());
el.table = el.tn;
el.non_unique = el.uniqueness === 'NONUNIQUE' ? 1 : 0;
el.non_unique_original = el.uniqueness === 'NONUNIQUE' ? 1 : 0;
@ -686,7 +686,7 @@ class OracleClient extends KnexClient {
for (let i = 0; i < response.length; i++) {
let el = response[i];
el = _.mapKeys(el, (_v, k) => k.toLowerCase());
el = mapKeys(el, (_v, k) => k.toLowerCase());
el.table = el.tn;
if (el.cst === 'P') el.cst = 'Primary Key';
if (el.cst === 'U') el.cst = 'Unique';
@ -758,7 +758,7 @@ class OracleClient extends KnexClient {
for (let i = 0; i < response.length; i++) {
let el = response[i];
el = _.mapKeys(el, (_v, k) => k.toLowerCase());
el = mapKeys(el, (_v, k) => k.toLowerCase());
el.rtn = el.r_table_name;
el.rcn = el.r_column_name;
el.non_unique = el.uniqueness === 'NONUNIQUE';
@ -811,7 +811,7 @@ class OracleClient extends KnexClient {
for (let i = 0; i < response.length; i++) {
let el = response[i];
el = _.mapKeys(el, (_v, k) => k.toLowerCase());
el = mapKeys(el, (_v, k) => k.toLowerCase());
el.rtn = el.r_table_name;
el.rcn = el.r_column_name;
el.non_unique = el.uniqueness === 'NONUNIQUE';
@ -862,7 +862,7 @@ class OracleClient extends KnexClient {
for (let i = 0; i < response.length; i++) {
let el = response[i];
el = _.mapKeys(el, (_v, k) => k.toLowerCase());
el = mapKeys(el, (_v, k) => k.toLowerCase());
el.trigger = el.trigger_name;
el.table = el.object_name;
el.event = el.triggering_event;
@ -910,7 +910,7 @@ class OracleClient extends KnexClient {
for (let i = 0; i < response.length; i++) {
let el = response[i];
el = _.mapKeys(el, (_v, k) => k.toLowerCase());
el = mapKeys(el, (_v, k) => k.toLowerCase());
el.function_name = el.object_name;
el.type = el.object_type;
response[i] = el;
@ -956,7 +956,7 @@ class OracleClient extends KnexClient {
for (let i = 0; i < response.length; i++) {
let el = response[i];
el = _.mapKeys(el, (_v, k) => k.toLowerCase());
el = mapKeys(el, (_v, k) => k.toLowerCase());
el.procedure_name = el.object_name;
el.type = el.object_type;
response[i] = el;
@ -996,7 +996,7 @@ class OracleClient extends KnexClient {
for (let i = 0; i < response.length; i++) {
let el = response[i];
el = _.mapKeys(el, (_v, k) => k.toLowerCase());
el = mapKeys(el, (_v, k) => k.toLowerCase());
el.view_name = el.object_name;
response[i] = el;
}
@ -1038,7 +1038,7 @@ class OracleClient extends KnexClient {
let script = '';
for (let i = 0; i < response.length; i++) {
let el = response[i];
el = _.mapKeys(el, (_v, k) => k.toLowerCase());
el = mapKeys(el, (_v, k) => k.toLowerCase());
el.function_name = el.name;
response[i] = el;
script += el.text;
@ -1084,7 +1084,7 @@ class OracleClient extends KnexClient {
let script = '';
for (let i = 0; i < response.length; i++) {
let el = response[i];
el = _.mapKeys(el, (_v, k) => k.toLowerCase());
el = mapKeys(el, (_v, k) => k.toLowerCase());
el.procedure_name = el.name;
response[i] = el;
script += el.text;
@ -1124,7 +1124,7 @@ class OracleClient extends KnexClient {
for (let i = 0; i < response.length; i++) {
let el = response[i];
el = _.mapKeys(el, (_v, k) => k.toLowerCase());
el = mapKeys(el, (_v, k) => k.toLowerCase());
el.view_name = el.object_name;
el.view_definition = el.text;
response[i] = el;
@ -1157,7 +1157,7 @@ class OracleClient extends KnexClient {
for (let i = 0; i < response.length; i++) {
let el = response[i];
el = _.mapKeys(el, (_v, k) => k.toLowerCase());
el = mapKeys(el, (_v, k) => k.toLowerCase());
el.trigger = el.trigger_name;
el.table = el.object_name;
el.event = el.triggering_event;
@ -1622,7 +1622,7 @@ class OracleClient extends KnexClient {
let downQuery = '';
for (let i = 0; i < args.columns.length; ++i) {
const oldColumn = lodash.find(originalColumns, {
const oldColumn = find(originalColumns, {
cn: args.columns[i].cno,
});

11
packages/nocodb/src/lib/db/sql-client/lib/pg/PgClient.ts

@ -1,12 +1,13 @@
import { nanoid } from 'nanoid';
import knex from 'knex';
import _ from 'lodash';
import KnexClient from '../KnexClient';
import Debug from '../../../util/Debug';
import Result from '../../../util/Result';
import queries from './pg.queries';
import lodash from 'lodash';
import isEmpty from 'lodash/isEmpty';
import mapKeys from 'lodash/mapKeys';
import find from 'lodash/find';
const log = new Debug('PGClient');
class PGClient extends KnexClient {
@ -1429,7 +1430,7 @@ class PGClient extends KnexClient {
if (response.length === 2) {
for (let i = 0; i < response[0].length; ++i) {
let procedure = response[0][i];
procedure = _.mapKeys(procedure, (_v, k) => k.toLowerCase());
procedure = mapKeys(procedure, (_v, k) => k.toLowerCase());
procedure.create_procedure = procedure['create procedure'];
rows.push(procedure);
}
@ -1642,7 +1643,7 @@ class PGClient extends KnexClient {
*/
async _getQuery(args) {
try {
if (_.isEmpty(this._version)) {
if (isEmpty(this._version)) {
const result = await this.version();
this._version = result.data.object;
log.debug(
@ -2204,7 +2205,7 @@ class PGClient extends KnexClient {
let downQuery = '';
for (let i = 0; i < args.columns.length; ++i) {
const oldColumn = lodash.find(originalColumns, {
const oldColumn = find(originalColumns, {
cn: args.columns[i].cno,
});

17
packages/nocodb/src/lib/db/sql-client/lib/sqlite/SqliteClient.ts

@ -5,8 +5,9 @@ import KnexClient from '../KnexClient';
import Debug from '../../../util/Debug';
import Result from '../../../util/Result';
import queries from './sqlite.queries';
import lodash from 'lodash';
import _ from 'lodash';
import isEmpty from 'lodash/isEmpty';
import mapKeys from 'lodash/mapKeys';
import find from 'lodash/find';
import { customAlphabet } from 'nanoid';
const nanoid = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyz_', 6);
@ -681,7 +682,7 @@ class SqliteClient extends KnexClient {
for (let i = 0; i < response[0].length; ++i) {
let fn = response[0][i];
fn = _.mapKeys(fn, function (_v, k) {
fn = mapKeys(fn, function (_v, k) {
return k.toLowerCase();
});
fn.function_name = fn.name;
@ -735,7 +736,7 @@ class SqliteClient extends KnexClient {
for (let i = 0; i < response[0].length; ++i) {
let procedure = response[0][i];
procedure = _.mapKeys(procedure, function (_v, k) {
procedure = mapKeys(procedure, function (_v, k) {
return k.toLowerCase();
});
procedure.procedure_name = procedure.name;
@ -819,7 +820,7 @@ class SqliteClient extends KnexClient {
for (let i = 0; i < response[0].length; ++i) {
let _function = response[0][i];
_function = _.mapKeys(_function, function (_v, k) {
_function = mapKeys(_function, function (_v, k) {
return k.toLowerCase();
});
@ -871,7 +872,7 @@ class SqliteClient extends KnexClient {
for (let i = 0; i < response[0].length; ++i) {
let procedure = response[0][i];
procedure = _.mapKeys(procedure, function (_v, k) {
procedure = mapKeys(procedure, function (_v, k) {
return k.toLowerCase();
});
@ -1034,7 +1035,7 @@ class SqliteClient extends KnexClient {
*/
async _getQuery(args) {
try {
if (_.isEmpty(this._version)) {
if (isEmpty(this._version)) {
const result = await this.version();
this._version = result.data.object;
log.debug(
@ -1494,7 +1495,7 @@ class SqliteClient extends KnexClient {
let downQuery = '';
for (let i = 0; i < args.columns.length; ++i) {
const oldColumn = lodash.find(originalColumns, {
const oldColumn = find(originalColumns, {
cn: args.columns[i].cno,
});

Loading…
Cancel
Save