mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
reduce dbgate-tools package size
This commit is contained in:
parent
5862a2cdc4
commit
556a35f4ba
@ -1,23 +1,20 @@
|
|||||||
{
|
{
|
||||||
"version": "1.0.1",
|
"version": "1.0.3",
|
||||||
"name": "dbgate-tools",
|
"name": "dbgate-tools",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"typings": "lib/index.d.ts",
|
"typings": "lib/index.d.ts",
|
||||||
|
|
||||||
"homepage": "https://dbgate.org/",
|
"homepage": "https://dbgate.org/",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/dbshell/dbgate.git"
|
"url": "https://github.com/dbshell/dbgate.git"
|
||||||
},
|
},
|
||||||
"funding": "https://www.paypal.com/paypalme/JanProchazkaCz/30eur",
|
"funding": "https://www.paypal.com/paypalme/JanProchazkaCz/30eur",
|
||||||
"author": "Jan Prochazka",
|
"author": "Jan Prochazka",
|
||||||
"license": "GPL",
|
"license": "GPL",
|
||||||
|
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"sql",
|
"sql",
|
||||||
"dbgate"
|
"dbgate"
|
||||||
],
|
],
|
||||||
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"prepare": "yarn build",
|
"prepare": "yarn build",
|
||||||
"build": "tsc",
|
"build": "tsc",
|
||||||
@ -28,14 +25,13 @@
|
|||||||
"lib"
|
"lib"
|
||||||
],
|
],
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"dbgate-types": "^1.0.0",
|
|
||||||
"@types/node": "^13.7.0",
|
"@types/node": "^13.7.0",
|
||||||
|
"dbgate-types": "^1.0.0",
|
||||||
"jest": "^24.9.0",
|
"jest": "^24.9.0",
|
||||||
"ts-jest": "^25.2.1",
|
"ts-jest": "^25.2.1",
|
||||||
"typescript": "^3.7.5"
|
"typescript": "^3.7.5"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"lodash": "^4.17.15",
|
"lodash": "^4.17.15"
|
||||||
"moment": "^2.24.0"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import { DatabaseInfo, DatabaseModification, EngineDriver } from 'dbgate-types';
|
import { DatabaseInfo, DatabaseModification, EngineDriver } from 'dbgate-types';
|
||||||
import _ from 'lodash';
|
import _sortBy from 'lodash/sortBy';
|
||||||
import fp from 'lodash/fp';
|
import _groupBy from 'lodash/groupBy';
|
||||||
|
import _pick from 'lodash/pick';
|
||||||
|
import fp_pick from 'lodash/fp/pick';
|
||||||
|
|
||||||
export class DatabaseAnalyser {
|
export class DatabaseAnalyser {
|
||||||
structure: DatabaseInfo;
|
structure: DatabaseInfo;
|
||||||
@ -54,7 +56,7 @@ export class DatabaseAnalyser {
|
|||||||
const newArray = newlyAnalysed[field] || [];
|
const newArray = newlyAnalysed[field] || [];
|
||||||
const addedChangedIds = newArray.map((x) => extractObjectId(x));
|
const addedChangedIds = newArray.map((x) => extractObjectId(x));
|
||||||
const removeAllIds = [...removedIds, ...addedChangedIds];
|
const removeAllIds = [...removedIds, ...addedChangedIds];
|
||||||
res[field] = _.sortBy(
|
res[field] = _sortBy(
|
||||||
[...this.structure[field].filter((x) => !removeAllIds.includes(extractObjectId(x))), ...newArray],
|
[...this.structure[field].filter((x) => !removeAllIds.includes(extractObjectId(x))), ...newArray],
|
||||||
(x) => x.pureName
|
(x) => x.pureName
|
||||||
);
|
);
|
||||||
@ -92,17 +94,17 @@ export class DatabaseAnalyser {
|
|||||||
const filtered = pkColumns.filter(DatabaseAnalyser.byTableFilter(table));
|
const filtered = pkColumns.filter(DatabaseAnalyser.byTableFilter(table));
|
||||||
if (filtered.length == 0) return undefined;
|
if (filtered.length == 0) return undefined;
|
||||||
return {
|
return {
|
||||||
..._.pick(filtered[0], ['constraintName', 'schemaName', 'pureName']),
|
..._pick(filtered[0], ['constraintName', 'schemaName', 'pureName']),
|
||||||
constraintType: 'primaryKey',
|
constraintType: 'primaryKey',
|
||||||
columns: filtered.map(fp.pick('columnName')),
|
columns: filtered.map(fp_pick('columnName')),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
static extractForeignKeys(table, fkColumns) {
|
static extractForeignKeys(table, fkColumns) {
|
||||||
const grouped = _.groupBy(fkColumns.filter(DatabaseAnalyser.byTableFilter(table)), 'constraintName');
|
const grouped = _groupBy(fkColumns.filter(DatabaseAnalyser.byTableFilter(table)), 'constraintName');
|
||||||
return _.keys(grouped).map((constraintName) => ({
|
return Object.keys(grouped).map((constraintName) => ({
|
||||||
constraintName,
|
constraintName,
|
||||||
constraintType: 'foreignKey',
|
constraintType: 'foreignKey',
|
||||||
..._.pick(grouped[constraintName][0], [
|
..._pick(grouped[constraintName][0], [
|
||||||
'constraintName',
|
'constraintName',
|
||||||
'schemaName',
|
'schemaName',
|
||||||
'pureName',
|
'pureName',
|
||||||
@ -111,7 +113,7 @@ export class DatabaseAnalyser {
|
|||||||
'updateAction',
|
'updateAction',
|
||||||
'deleteAction',
|
'deleteAction',
|
||||||
]),
|
]),
|
||||||
columns: grouped[constraintName].map(fp.pick(['columnName', 'refColumnName'])),
|
columns: grouped[constraintName].map(fp_pick(['columnName', 'refColumnName'])),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,9 @@ import {
|
|||||||
TableInfo,
|
TableInfo,
|
||||||
TransformType,
|
TransformType,
|
||||||
} from 'dbgate-types';
|
} from 'dbgate-types';
|
||||||
import _ from 'lodash';
|
import _isString from 'lodash/isString'
|
||||||
import moment from 'moment';
|
import _isNumber from 'lodash/isNumber'
|
||||||
|
import _isDate from 'lodash/isDate'
|
||||||
|
|
||||||
export class SqlDumper {
|
export class SqlDumper {
|
||||||
s = '';
|
s = '';
|
||||||
@ -47,9 +48,9 @@ export class SqlDumper {
|
|||||||
if (value === null) this.putRaw('NULL');
|
if (value === null) this.putRaw('NULL');
|
||||||
if (value === true) this.putRaw('1');
|
if (value === true) this.putRaw('1');
|
||||||
if (value === false) this.putRaw('0');
|
if (value === false) this.putRaw('0');
|
||||||
else if (_.isString(value)) this.putStringValue(value);
|
else if (_isString(value)) this.putStringValue(value);
|
||||||
else if (_.isNumber(value)) this.putRaw(value.toString());
|
else if (_isNumber(value)) this.putRaw(value.toString());
|
||||||
else if (_.isDate(value)) this.putStringValue(moment(value).toISOString());
|
else if (_isDate(value)) this.putStringValue(new Date(value).toISOString());
|
||||||
}
|
}
|
||||||
putCmd(format, ...args) {
|
putCmd(format, ...args) {
|
||||||
this.put(format, ...args);
|
this.put(format, ...args);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { EngineDriver } from 'dbgate-types';
|
import { EngineDriver } from 'dbgate-types';
|
||||||
import _ from 'lodash';
|
import _intersection from 'lodash/intersection';
|
||||||
import { prepareTableForImport } from './tableTransforms';
|
import { prepareTableForImport } from './tableTransforms';
|
||||||
|
|
||||||
export function createBulkInsertStreamBase(driver, stream, pool, name, options): any {
|
export function createBulkInsertStreamBase(driver, stream, pool, name, options): any {
|
||||||
@ -43,7 +43,7 @@ export function createBulkInsertStreamBase(driver, stream, pool, name, options):
|
|||||||
await driver.query(pool, `TRUNCATE TABLE ${fullNameQuoted}`);
|
await driver.query(pool, `TRUNCATE TABLE ${fullNameQuoted}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.columnNames = _.intersection(
|
this.columnNames = _intersection(
|
||||||
structure.columns.map((x) => x.columnName),
|
structure.columns.map((x) => x.columnName),
|
||||||
writable.structure.columns.map((x) => x.columnName)
|
writable.structure.columns.map((x) => x.columnName)
|
||||||
);
|
);
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
import { createBulkInsertStreamBase } from './createBulkInsertStreamBase';
|
|
||||||
|
|
||||||
export const driverBase = {
|
export const driverBase = {
|
||||||
analyserClass: null,
|
analyserClass: null,
|
||||||
dumperClass: null,
|
dumperClass: null,
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import _ from 'lodash';
|
import _camelCase from 'lodash/camelCase';
|
||||||
|
|
||||||
export function extractShellApiPlugins(functionName, props): string[] {
|
export function extractShellApiPlugins(functionName, props): string[] {
|
||||||
const res = [];
|
const res = [];
|
||||||
@ -18,7 +18,7 @@ export function extractShellApiPlugins(functionName, props): string[] {
|
|||||||
export function extractShellApiFunctionName(functionName) {
|
export function extractShellApiFunctionName(functionName) {
|
||||||
const nsMatch = functionName.match(/^([^@]+)@([^@]+)/);
|
const nsMatch = functionName.match(/^([^@]+)@([^@]+)/);
|
||||||
if (nsMatch) {
|
if (nsMatch) {
|
||||||
return `${_.camelCase(nsMatch[2])}.shellApi.${nsMatch[1]}`;
|
return `${_camelCase(nsMatch[2])}.shellApi.${nsMatch[1]}`;
|
||||||
}
|
}
|
||||||
return `dbgateApi.${functionName}`;
|
return `dbgateApi.${functionName}`;
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { TableInfo } from 'dbgate-types';
|
import { TableInfo } from 'dbgate-types';
|
||||||
import _ from 'lodash';
|
import _cloneDeep from 'lodash/cloneDeep';
|
||||||
|
|
||||||
export function prepareTableForImport(table: TableInfo): TableInfo {
|
export function prepareTableForImport(table: TableInfo): TableInfo {
|
||||||
const res = _.cloneDeep(table);
|
const res = _cloneDeep(table);
|
||||||
res.foreignKeys = [];
|
res.foreignKeys = [];
|
||||||
if (res.primaryKey) res.primaryKey.constraintName = null;
|
if (res.primaryKey) res.primaryKey.constraintName = null;
|
||||||
return res;
|
return res;
|
||||||
|
Loading…
Reference in New Issue
Block a user