mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 00:56:02 +00:00
prettier
This commit is contained in:
@@ -45,7 +45,7 @@ export function findExistingChangeSetItem(
|
||||
return [
|
||||
'inserts',
|
||||
changeSet.inserts.find(
|
||||
(x) =>
|
||||
x =>
|
||||
x.pureName == definition.pureName &&
|
||||
x.schemaName == definition.schemaName &&
|
||||
x.insertedRowIndex == definition.insertedRowIndex
|
||||
@@ -53,7 +53,7 @@ export function findExistingChangeSetItem(
|
||||
];
|
||||
} else {
|
||||
const inUpdates = changeSet.updates.find(
|
||||
(x) =>
|
||||
x =>
|
||||
x.pureName == definition.pureName &&
|
||||
x.schemaName == definition.schemaName &&
|
||||
_.isEqual(x.condition, definition.condition)
|
||||
@@ -61,7 +61,7 @@ export function findExistingChangeSetItem(
|
||||
if (inUpdates) return ['updates', inUpdates];
|
||||
|
||||
const inDeletes = changeSet.deletes.find(
|
||||
(x) =>
|
||||
x =>
|
||||
x.pureName == definition.pureName &&
|
||||
x.schemaName == definition.schemaName &&
|
||||
_.isEqual(x.condition, definition.condition)
|
||||
@@ -86,7 +86,7 @@ export function setChangeSetValue(
|
||||
if (existingItem) {
|
||||
return {
|
||||
...changeSet,
|
||||
[fieldName]: changeSet[fieldName].map((item) =>
|
||||
[fieldName]: changeSet[fieldName].map(item =>
|
||||
item == existingItem
|
||||
? {
|
||||
...item,
|
||||
@@ -167,8 +167,8 @@ export function batchUpdateChangeSet(
|
||||
|
||||
function extractFields(item: ChangeSetItem, allowNulls = true): UpdateField[] {
|
||||
return _.keys(item.fields)
|
||||
.filter((targetColumn) => allowNulls || item.fields[targetColumn] != null)
|
||||
.map((targetColumn) => ({
|
||||
.filter(targetColumn => allowNulls || item.fields[targetColumn] != null)
|
||||
.map(targetColumn => ({
|
||||
targetColumn,
|
||||
exprType: 'value',
|
||||
value: item.fields[targetColumn],
|
||||
@@ -183,11 +183,11 @@ function insertToSql(
|
||||
if (fields.length == 0) return null;
|
||||
let autoInc = false;
|
||||
if (dbinfo) {
|
||||
const table = dbinfo.tables.find((x) => x.schemaName == item.schemaName && x.pureName == item.pureName);
|
||||
const table = dbinfo.tables.find(x => x.schemaName == item.schemaName && x.pureName == item.pureName);
|
||||
if (table) {
|
||||
const autoIncCol = table.columns.find((x) => x.autoIncrement);
|
||||
const autoIncCol = table.columns.find(x => x.autoIncrement);
|
||||
console.log('autoIncCol', autoIncCol);
|
||||
if (autoIncCol && fields.find((x) => x.targetColumn == autoIncCol.columnName)) {
|
||||
if (autoIncCol && fields.find(x => x.targetColumn == autoIncCol.columnName)) {
|
||||
autoInc = true;
|
||||
}
|
||||
}
|
||||
@@ -222,7 +222,7 @@ function insertToSql(
|
||||
function extractCondition(item: ChangeSetItem): Condition {
|
||||
return {
|
||||
conditionType: 'and',
|
||||
conditions: _.keys(item.condition).map((columnName) => ({
|
||||
conditions: _.keys(item.condition).map(columnName => ({
|
||||
conditionType: 'binary',
|
||||
operator: '=',
|
||||
left: {
|
||||
@@ -273,7 +273,7 @@ function deleteToSql(item: ChangeSetItem): Delete {
|
||||
export function changeSetToSql(changeSet: ChangeSet, dbinfo: DatabaseInfo): Command[] {
|
||||
return _.compact(
|
||||
_.flatten([
|
||||
...changeSet.inserts.map((item) => insertToSql(item, dbinfo)) as any,
|
||||
...(changeSet.inserts.map(item => insertToSql(item, dbinfo)) as any),
|
||||
...changeSet.updates.map(updateToSql),
|
||||
...changeSet.deletes.map(deleteToSql),
|
||||
])
|
||||
@@ -289,7 +289,7 @@ export function revertChangeSetRowChanges(changeSet: ChangeSet, definition: Chan
|
||||
if (item)
|
||||
return {
|
||||
...changeSet,
|
||||
[field]: changeSet[field].filter((x) => x != item),
|
||||
[field]: changeSet[field].filter(x => x != item),
|
||||
};
|
||||
return changeSet;
|
||||
}
|
||||
@@ -321,8 +321,8 @@ export function deleteChangeSetRows(changeSet: ChangeSet, definition: ChangeSetR
|
||||
export function getChangeSetInsertedRows(changeSet: ChangeSet, name?: NamedObjectInfo) {
|
||||
if (!name) return [];
|
||||
if (!changeSet) return [];
|
||||
const rows = changeSet.inserts.filter((x) => x.pureName == name.pureName && x.schemaName == name.schemaName);
|
||||
const maxIndex = _.maxBy(rows, (x) => x.insertedRowIndex)?.insertedRowIndex;
|
||||
const rows = changeSet.inserts.filter(x => x.pureName == name.pureName && x.schemaName == name.schemaName);
|
||||
const maxIndex = _.maxBy(rows, x => x.insertedRowIndex)?.insertedRowIndex;
|
||||
if (maxIndex == null) return [];
|
||||
const res = Array(maxIndex + 1).fill({});
|
||||
for (const row of rows) {
|
||||
|
||||
@@ -24,7 +24,7 @@ export class FormViewDisplay {
|
||||
|
||||
addFilterColumn(column) {
|
||||
if (!column) return;
|
||||
this.setConfig((cfg) => ({
|
||||
this.setConfig(cfg => ({
|
||||
...cfg,
|
||||
formFilterColumns: [...(cfg.formFilterColumns || []), column.uniqueName],
|
||||
}));
|
||||
@@ -35,7 +35,7 @@ export class FormViewDisplay {
|
||||
const value = rowData[column.uniqueName];
|
||||
const expr = getFilterValueExpression(value, column.dataType);
|
||||
if (expr) {
|
||||
this.setConfig((cfg) => ({
|
||||
this.setConfig(cfg => ({
|
||||
...cfg,
|
||||
filters: {
|
||||
...cfg.filters,
|
||||
@@ -46,7 +46,7 @@ export class FormViewDisplay {
|
||||
}
|
||||
|
||||
setFilter(uniqueName, value) {
|
||||
this.setConfig((cfg) => ({
|
||||
this.setConfig(cfg => ({
|
||||
...cfg,
|
||||
filters: {
|
||||
...cfg.filters,
|
||||
@@ -58,16 +58,16 @@ export class FormViewDisplay {
|
||||
|
||||
removeFilter(uniqueName) {
|
||||
const reloadRequired = !!this.config.filters[uniqueName];
|
||||
this.setConfig((cfg) => ({
|
||||
this.setConfig(cfg => ({
|
||||
...cfg,
|
||||
formFilterColumns: (cfg.formFilterColumns || []).filter((x) => x != uniqueName),
|
||||
formFilterColumns: (cfg.formFilterColumns || []).filter(x => x != uniqueName),
|
||||
filters: _.omit(cfg.filters || [], uniqueName),
|
||||
}));
|
||||
if (reloadRequired) this.reload();
|
||||
}
|
||||
|
||||
reload() {
|
||||
this.setCache((cache) => ({
|
||||
this.setCache(cache => ({
|
||||
// ...cache,
|
||||
...createGridCache(),
|
||||
refreshTime: new Date().getTime(),
|
||||
@@ -84,7 +84,7 @@ export class FormViewDisplay {
|
||||
requestKeyValue(columnName, value) {
|
||||
if (this.getKeyValue(columnName) == value) return;
|
||||
|
||||
this.setConfig((cfg) => ({
|
||||
this.setConfig(cfg => ({
|
||||
...cfg,
|
||||
formViewKeyRequested: {
|
||||
...cfg.formViewKey,
|
||||
@@ -101,13 +101,13 @@ export class FormViewDisplay {
|
||||
}
|
||||
const formViewKey = _.pick(
|
||||
row,
|
||||
this.baseTable.primaryKey.columns.map((x) => x.columnName)
|
||||
this.baseTable.primaryKey.columns.map(x => x.columnName)
|
||||
);
|
||||
return formViewKey;
|
||||
}
|
||||
|
||||
cancelRequestKey(rowData) {
|
||||
this.setConfig((cfg) => ({
|
||||
this.setConfig(cfg => ({
|
||||
...cfg,
|
||||
formViewKeyRequested: null,
|
||||
formViewKey: rowData ? this.extractKey(rowData) : cfg.formViewKey,
|
||||
|
||||
@@ -21,15 +21,15 @@ export class FreeTableGridDisplay extends GridDisplay {
|
||||
getDisplayColumns(model: FreeTableModel) {
|
||||
return (
|
||||
model?.structure?.columns
|
||||
?.map((col) => this.getDisplayColumn(col))
|
||||
?.map((col) => ({
|
||||
?.map(col => this.getDisplayColumn(col))
|
||||
?.map(col => ({
|
||||
...col,
|
||||
isChecked: this.isColumnChecked(col),
|
||||
})) || []
|
||||
);
|
||||
}
|
||||
|
||||
getDisplayColumn( col: ColumnInfo) {
|
||||
getDisplayColumn(col: ColumnInfo) {
|
||||
const uniquePath = [col.columnName];
|
||||
const uniqueName = uniquePath.join('.');
|
||||
return {
|
||||
|
||||
@@ -71,7 +71,7 @@ export abstract class GridDisplay {
|
||||
}
|
||||
|
||||
focusColumn(uniqueName: string) {
|
||||
this.setConfig((cfg) => ({
|
||||
this.setConfig(cfg => ({
|
||||
...cfg,
|
||||
focusedColumn: uniqueName,
|
||||
}));
|
||||
@@ -90,11 +90,11 @@ export abstract class GridDisplay {
|
||||
}
|
||||
|
||||
get allColumns() {
|
||||
return this.getColumns(null).filter((col) => col.isChecked || col.uniquePath.length == 1);
|
||||
return this.getColumns(null).filter(col => col.isChecked || col.uniquePath.length == 1);
|
||||
}
|
||||
|
||||
reload() {
|
||||
this.setCache((cache) => ({
|
||||
this.setCache(cache => ({
|
||||
// ...cache,
|
||||
...createGridCache(),
|
||||
refreshTime: new Date().getTime(),
|
||||
@@ -104,34 +104,34 @@ export abstract class GridDisplay {
|
||||
includeInColumnSet(field: keyof GridConfigColumns, uniqueName: string, isIncluded: boolean) {
|
||||
// console.log('includeInColumnSet', field, uniqueName, isIncluded);
|
||||
if (isIncluded) {
|
||||
this.setConfig((cfg) => ({
|
||||
this.setConfig(cfg => ({
|
||||
...cfg,
|
||||
[field]: [...(cfg[field] || []), uniqueName],
|
||||
}));
|
||||
} else {
|
||||
this.setConfig((cfg) => ({
|
||||
this.setConfig(cfg => ({
|
||||
...cfg,
|
||||
[field]: (cfg[field] || []).filter((x) => x != uniqueName),
|
||||
[field]: (cfg[field] || []).filter(x => x != uniqueName),
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
showAllColumns() {
|
||||
this.setConfig((cfg) => ({
|
||||
this.setConfig(cfg => ({
|
||||
...cfg,
|
||||
hiddenColumns: [],
|
||||
}));
|
||||
}
|
||||
|
||||
hideAllColumns() {
|
||||
this.setConfig((cfg) => ({
|
||||
this.setConfig(cfg => ({
|
||||
...cfg,
|
||||
hiddenColumns: this.columns.map((x) => x.uniqueName),
|
||||
hiddenColumns: this.columns.map(x => x.uniqueName),
|
||||
}));
|
||||
}
|
||||
|
||||
get hiddenColumnIndexes() {
|
||||
return (this.config.hiddenColumns || []).map((x) => _.findIndex(this.columns, (y) => y.uniqueName == x));
|
||||
return (this.config.hiddenColumns || []).map(x => _.findIndex(this.columns, y => y.uniqueName == x));
|
||||
}
|
||||
|
||||
isColumnChecked(column: DisplayColumn) {
|
||||
@@ -179,10 +179,10 @@ export abstract class GridDisplay {
|
||||
applySortOnSelect(select: Select, displayedColumnInfo: DisplayedColumnInfo) {
|
||||
if (this.config.sort?.length > 0) {
|
||||
select.orderBy = this.config.sort
|
||||
.map((col) => ({ ...col, dispInfo: displayedColumnInfo[col.uniqueName] }))
|
||||
.map((col) => ({ ...col, expr: select.columns.find((x) => x.alias == col.uniqueName) }))
|
||||
.filter((col) => col.dispInfo && col.expr)
|
||||
.map((col) => ({
|
||||
.map(col => ({ ...col, dispInfo: displayedColumnInfo[col.uniqueName] }))
|
||||
.map(col => ({ ...col, expr: select.columns.find(x => x.alias == col.uniqueName) }))
|
||||
.filter(col => col.dispInfo && col.expr)
|
||||
.map(col => ({
|
||||
...col.expr,
|
||||
direction: col.order,
|
||||
}));
|
||||
@@ -194,16 +194,14 @@ export abstract class GridDisplay {
|
||||
}
|
||||
|
||||
get groupColumns() {
|
||||
return this.isGrouped
|
||||
? _.keys(_.pickBy(this.config.grouping, (v) => v == 'GROUP' || v.startsWith('GROUP:')))
|
||||
: null;
|
||||
return this.isGrouped ? _.keys(_.pickBy(this.config.grouping, v => v == 'GROUP' || v.startsWith('GROUP:'))) : null;
|
||||
}
|
||||
|
||||
applyGroupOnSelect(select: Select, displayedColumnInfo: DisplayedColumnInfo) {
|
||||
const groupColumns = this.groupColumns;
|
||||
if (groupColumns && groupColumns.length > 0) {
|
||||
// @ts-ignore
|
||||
select.groupBy = groupColumns.map((col) => {
|
||||
select.groupBy = groupColumns.map(col => {
|
||||
const colExpr: Expression = {
|
||||
exprType: 'column',
|
||||
columnName: displayedColumnInfo[col].columnName,
|
||||
@@ -257,16 +255,16 @@ export abstract class GridDisplay {
|
||||
};
|
||||
}
|
||||
}
|
||||
select.columns = select.columns.filter((x) => x.alias);
|
||||
select.columns = select.columns.filter(x => x.alias);
|
||||
}
|
||||
}
|
||||
|
||||
getColumns(columnFilter) {
|
||||
return this.columns.filter((col) => filterName(columnFilter, col.columnName));
|
||||
return this.columns.filter(col => filterName(columnFilter, col.columnName));
|
||||
}
|
||||
|
||||
getGridColumns() {
|
||||
return this.getColumns(null).filter((x) => this.isColumnChecked(x));
|
||||
return this.getColumns(null).filter(x => this.isColumnChecked(x));
|
||||
}
|
||||
|
||||
isExpandedColumn(uniqueName: string) {
|
||||
@@ -282,7 +280,7 @@ export abstract class GridDisplay {
|
||||
}
|
||||
|
||||
setFilter(uniqueName, value) {
|
||||
this.setConfig((cfg) => ({
|
||||
this.setConfig(cfg => ({
|
||||
...cfg,
|
||||
filters: {
|
||||
...cfg.filters,
|
||||
@@ -293,7 +291,7 @@ export abstract class GridDisplay {
|
||||
}
|
||||
|
||||
setFilters(dct) {
|
||||
this.setConfig((cfg) => ({
|
||||
this.setConfig(cfg => ({
|
||||
...cfg,
|
||||
filters: {
|
||||
...cfg.filters,
|
||||
@@ -304,7 +302,7 @@ export abstract class GridDisplay {
|
||||
}
|
||||
|
||||
setSort(uniqueName, order) {
|
||||
this.setConfig((cfg) => ({
|
||||
this.setConfig(cfg => ({
|
||||
...cfg,
|
||||
sort: [{ uniqueName, order }],
|
||||
}));
|
||||
@@ -312,7 +310,7 @@ export abstract class GridDisplay {
|
||||
}
|
||||
|
||||
setGrouping(uniqueName, groupFunc: GroupFunc) {
|
||||
this.setConfig((cfg) => ({
|
||||
this.setConfig(cfg => ({
|
||||
...cfg,
|
||||
grouping: groupFunc
|
||||
? {
|
||||
@@ -327,7 +325,7 @@ export abstract class GridDisplay {
|
||||
getGrouping(uniqueName): GroupFunc {
|
||||
if (this.isGrouped) {
|
||||
if (this.config.grouping[uniqueName]) return this.config.grouping[uniqueName];
|
||||
const column = this.baseTable.columns.find((x) => x.columnName == uniqueName);
|
||||
const column = this.baseTable.columns.find(x => x.columnName == uniqueName);
|
||||
if (isTypeLogical(column?.dataType)) return 'COUNT DISTINCT';
|
||||
if (column?.autoIncrement) return 'COUNT';
|
||||
return 'MAX';
|
||||
@@ -336,7 +334,7 @@ export abstract class GridDisplay {
|
||||
}
|
||||
|
||||
clearGrouping() {
|
||||
this.setConfig((cfg) => ({
|
||||
this.setConfig(cfg => ({
|
||||
...cfg,
|
||||
grouping: {},
|
||||
}));
|
||||
@@ -344,7 +342,7 @@ export abstract class GridDisplay {
|
||||
}
|
||||
|
||||
getSortOrder(uniqueName) {
|
||||
return this.config.sort.find((x) => x.uniqueName == uniqueName)?.order;
|
||||
return this.config.sort.find(x => x.uniqueName == uniqueName)?.order;
|
||||
}
|
||||
|
||||
get filterCount() {
|
||||
@@ -352,7 +350,7 @@ export abstract class GridDisplay {
|
||||
}
|
||||
|
||||
clearFilters() {
|
||||
this.setConfig((cfg) => ({
|
||||
this.setConfig(cfg => ({
|
||||
...cfg,
|
||||
filters: {},
|
||||
}));
|
||||
@@ -365,7 +363,7 @@ export abstract class GridDisplay {
|
||||
}
|
||||
|
||||
getChangeSetField(row, uniqueName, insertedRowIndex): ChangeSetFieldDefinition {
|
||||
const col = this.columns.find((x) => x.uniqueName == uniqueName);
|
||||
const col = this.columns.find(x => x.uniqueName == uniqueName);
|
||||
if (!col) return null;
|
||||
if (!this.baseTable) return null;
|
||||
if (this.baseTable.pureName != col.pureName || this.baseTable.schemaName != col.schemaName) return null;
|
||||
@@ -398,7 +396,7 @@ export abstract class GridDisplay {
|
||||
const select: Select = {
|
||||
commandType: 'select',
|
||||
from: { name, alias: 'basetbl' },
|
||||
columns: columns.map((col) => ({
|
||||
columns: columns.map(col => ({
|
||||
exprType: 'column',
|
||||
alias: col.columnName,
|
||||
source: { alias: 'basetbl' },
|
||||
@@ -413,7 +411,7 @@ export abstract class GridDisplay {
|
||||
],
|
||||
};
|
||||
const displayedColumnInfo = _.keyBy(
|
||||
this.columns.map((col) => ({ ...col, sourceAlias: 'basetbl' })),
|
||||
this.columns.map(col => ({ ...col, sourceAlias: 'basetbl' })),
|
||||
'uniqueName'
|
||||
);
|
||||
this.processReferences(select, displayedColumnInfo, options);
|
||||
@@ -442,7 +440,7 @@ export abstract class GridDisplay {
|
||||
}
|
||||
|
||||
resizeColumn(uniqueName: string, computedSize: number, diff: number) {
|
||||
this.setConfig((cfg) => {
|
||||
this.setConfig(cfg => {
|
||||
const columnWidths = {
|
||||
...cfg.columnWidths,
|
||||
};
|
||||
@@ -495,7 +493,7 @@ export abstract class GridDisplay {
|
||||
if (!filters) return null;
|
||||
const conditions = [];
|
||||
for (const name in filters) {
|
||||
const column = this.columns.find((x) => (x.columnName = name));
|
||||
const column = this.columns.find(x => (x.columnName = name));
|
||||
if (!column) continue;
|
||||
const filterType = getFilterType(column.dataType);
|
||||
try {
|
||||
@@ -525,13 +523,13 @@ export abstract class GridDisplay {
|
||||
if (!primaryKey) return;
|
||||
const { columns } = primaryKey;
|
||||
|
||||
this.setConfig((cfg) => ({
|
||||
this.setConfig(cfg => ({
|
||||
...cfg,
|
||||
isFormView: true,
|
||||
formViewKey: rowData
|
||||
? _.pick(
|
||||
rowData,
|
||||
columns.map((x) => x.columnName)
|
||||
columns.map(x => x.columnName)
|
||||
)
|
||||
: null,
|
||||
formViewKeyRequested: null,
|
||||
|
||||
@@ -16,7 +16,7 @@ export class JslGridDisplay extends GridDisplay {
|
||||
this.filterable = true;
|
||||
|
||||
this.columns = columns
|
||||
.map((col) => ({
|
||||
.map(col => ({
|
||||
columnName: col.columnName,
|
||||
headerText: col.columnName,
|
||||
uniqueName: col.columnName,
|
||||
@@ -26,7 +26,7 @@ export class JslGridDisplay extends GridDisplay {
|
||||
pureName: null,
|
||||
schemaName: null,
|
||||
}))
|
||||
?.map((col) => ({
|
||||
?.map(col => ({
|
||||
...col,
|
||||
isChecked: this.isColumnChecked(col),
|
||||
}));
|
||||
|
||||
@@ -168,7 +168,7 @@ export class TableFormViewDisplay extends FormViewDisplay {
|
||||
|
||||
navigate(row) {
|
||||
const formViewKey = this.extractKey(row);
|
||||
this.setConfig((cfg) => ({
|
||||
this.setConfig(cfg => ({
|
||||
...cfg,
|
||||
formViewKey,
|
||||
}));
|
||||
@@ -226,7 +226,7 @@ export class TableFormViewDisplay extends FormViewDisplay {
|
||||
}
|
||||
|
||||
getChangeSetField(row, uniqueName): ChangeSetFieldDefinition {
|
||||
const col = this.columns.find((x) => x.uniqueName == uniqueName);
|
||||
const col = this.columns.find(x => x.uniqueName == uniqueName);
|
||||
if (!col) return null;
|
||||
if (!this.baseTable) return null;
|
||||
if (this.baseTable.pureName != col.pureName || this.baseTable.schemaName != col.schemaName) return null;
|
||||
|
||||
@@ -36,8 +36,8 @@ export class TableGridDisplay extends GridDisplay {
|
||||
this.baseTable = this.table;
|
||||
if (this.table && this.table.columns) {
|
||||
this.changeSetKeyFields = this.table.primaryKey
|
||||
? this.table.primaryKey.columns.map((x) => x.columnName)
|
||||
: this.table.columns.map((x) => x.columnName);
|
||||
? this.table.primaryKey.columns.map(x => x.columnName)
|
||||
: this.table.columns.map(x => x.columnName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,15 +45,15 @@ export class TableGridDisplay extends GridDisplay {
|
||||
return (
|
||||
this.dbinfo &&
|
||||
this.dbinfo.tables &&
|
||||
this.dbinfo.tables.find((x) => x.pureName == pureName && x.schemaName == schemaName)
|
||||
this.dbinfo.tables.find(x => x.pureName == pureName && x.schemaName == schemaName)
|
||||
);
|
||||
}
|
||||
|
||||
getDisplayColumns(table: TableInfo, parentPath: string[]) {
|
||||
return (
|
||||
table?.columns
|
||||
?.map((col) => this.getDisplayColumn(table, col, parentPath))
|
||||
?.map((col) => ({
|
||||
?.map(col => this.getDisplayColumn(table, col, parentPath))
|
||||
?.map(col => ({
|
||||
...col,
|
||||
isChecked: this.isColumnChecked(col),
|
||||
hintColumnName: col.foreignKey ? `hint_${col.uniqueName}` : null,
|
||||
@@ -80,7 +80,7 @@ export class TableGridDisplay extends GridDisplay {
|
||||
|
||||
addReferenceToSelect(select: Select, parentAlias: string, column: DisplayColumn) {
|
||||
const childAlias = `${column.uniqueName}_ref`;
|
||||
if ((select.from.relations || []).find((x) => x.alias == childAlias)) return;
|
||||
if ((select.from.relations || []).find(x => x.alias == childAlias)) return;
|
||||
const table = this.getFkTarget(column);
|
||||
if (table && table.primaryKey) {
|
||||
select.from.relations = [
|
||||
@@ -120,7 +120,7 @@ export class TableGridDisplay extends GridDisplay {
|
||||
}
|
||||
const table = this.getFkTarget(column);
|
||||
if (table && table.columns && table.columns.length > 0 && table.primaryKey) {
|
||||
const hintColumn = table.columns.find((x) => x?.dataType?.toLowerCase()?.includes('char'));
|
||||
const hintColumn = table.columns.find(x => x?.dataType?.toLowerCase()?.includes('char'));
|
||||
if (hintColumn) {
|
||||
const parentUniqueName = column.uniquePath.slice(0, -1).join('.');
|
||||
this.addReferenceToSelect(select, parentUniqueName ? `${parentUniqueName}_ref` : 'basetbl', column);
|
||||
@@ -177,7 +177,7 @@ export class TableGridDisplay extends GridDisplay {
|
||||
}
|
||||
|
||||
getColumns(columnFilter) {
|
||||
return this.enrichExpandedColumns(this.columns.filter((col) => filterName(columnFilter, col.columnName)));
|
||||
return this.enrichExpandedColumns(this.columns.filter(col => filterName(columnFilter, col.columnName)));
|
||||
}
|
||||
|
||||
getDisplayColumn(table: TableInfo, col: ColumnInfo, parentPath: string[]) {
|
||||
@@ -191,10 +191,10 @@ export class TableGridDisplay extends GridDisplay {
|
||||
headerText: uniquePath.length == 1 ? col.columnName : `${table.pureName}.${col.columnName}`,
|
||||
uniqueName,
|
||||
uniquePath,
|
||||
isPrimaryKey: table.primaryKey && !!table.primaryKey.columns.find((x) => x.columnName == col.columnName),
|
||||
isPrimaryKey: table.primaryKey && !!table.primaryKey.columns.find(x => x.columnName == col.columnName),
|
||||
foreignKey:
|
||||
table.foreignKeys &&
|
||||
table.foreignKeys.find((fk) => fk.columns.length == 1 && fk.columns[0].columnName == col.columnName),
|
||||
table.foreignKeys.find(fk => fk.columns.length == 1 && fk.columns[0].columnName == col.columnName),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -23,8 +23,8 @@ export class ViewGridDisplay extends GridDisplay {
|
||||
getDisplayColumns(view: ViewInfo) {
|
||||
return (
|
||||
view?.columns
|
||||
?.map((col) => this.getDisplayColumn(view, col))
|
||||
?.map((col) => ({
|
||||
?.map(col => this.getDisplayColumn(view, col))
|
||||
?.map(col => ({
|
||||
...col,
|
||||
isChecked: this.isColumnChecked(col),
|
||||
})) || []
|
||||
|
||||
@@ -6,17 +6,17 @@ import moment from 'moment';
|
||||
import { MacroDefinition, MacroSelectedCell } from './MacroDefinition';
|
||||
|
||||
const getMacroFunction = {
|
||||
transformValue: (code) => `
|
||||
transformValue: code => `
|
||||
(value, args, modules, rowIndex, row, columnName) => {
|
||||
${code}
|
||||
}
|
||||
`,
|
||||
transformRows: (code) => `
|
||||
transformRows: code => `
|
||||
(rows, args, modules, selectedCells, cols, columns) => {
|
||||
${code}
|
||||
}
|
||||
`,
|
||||
transformData: (code) => `
|
||||
transformData: code => `
|
||||
(rows, args, modules, selectedCells, cols, columns) => {
|
||||
${code}
|
||||
}
|
||||
@@ -83,8 +83,8 @@ function runTramsformValue(
|
||||
}
|
||||
|
||||
function removePreviewRowFlags(rows) {
|
||||
rows = rows.filter((row) => row.__rowStatus != 'deleted');
|
||||
rows = rows.map((row) => {
|
||||
rows = rows.filter(row => row.__rowStatus != 'deleted');
|
||||
rows = rows.map(row => {
|
||||
if (row.__rowStatus || row.__modifiedFields || row.__insertedFields || row.__deletedFields)
|
||||
return _.omit(row, ['__rowStatus', '__modifiedFields', '__insertedFields', '__deletedFields']);
|
||||
return row;
|
||||
@@ -107,7 +107,7 @@ function runTramsformRows(
|
||||
macroArgs,
|
||||
modules,
|
||||
selectedCells,
|
||||
data.structure.columns.map((x) => x.columnName),
|
||||
data.structure.columns.map(x => x.columnName),
|
||||
data.structure.columns
|
||||
);
|
||||
if (!preview) {
|
||||
@@ -136,11 +136,11 @@ function runTramsformData(
|
||||
macroArgs,
|
||||
modules,
|
||||
selectedCells,
|
||||
data.structure.columns.map((x) => x.columnName),
|
||||
data.structure.columns.map(x => x.columnName),
|
||||
data.structure.columns
|
||||
);
|
||||
if (cols && !columns) {
|
||||
columns = cols.map((columnName) => ({ columnName }));
|
||||
columns = cols.map(columnName => ({ columnName }));
|
||||
}
|
||||
columns = _.uniqBy(columns, 'columnName');
|
||||
if (!preview) {
|
||||
|
||||
@@ -18,7 +18,7 @@ export function dumpSqlSelect(dmp: SqlDumper, cmd: Select) {
|
||||
if (cmd.columns) {
|
||||
if (cmd.selectAll) dmp.put('&n,');
|
||||
dmp.put('&>&n');
|
||||
dmp.putCollection(',&n', cmd.columns, (fld) => {
|
||||
dmp.putCollection(',&n', cmd.columns, fld => {
|
||||
dumpSqlExpression(dmp, fld);
|
||||
if (fld.alias) dmp.put(' ^as %i', fld.alias);
|
||||
});
|
||||
@@ -33,7 +33,7 @@ export function dumpSqlSelect(dmp: SqlDumper, cmd: Select) {
|
||||
}
|
||||
if (cmd.groupBy) {
|
||||
dmp.put('&n^group ^by ');
|
||||
dmp.putCollection(', ', cmd.groupBy, (expr) => dumpSqlExpression(dmp, expr));
|
||||
dmp.putCollection(', ', cmd.groupBy, expr => dumpSqlExpression(dmp, expr));
|
||||
dmp.put('&n');
|
||||
}
|
||||
if (cmd.having) {
|
||||
@@ -43,7 +43,7 @@ export function dumpSqlSelect(dmp: SqlDumper, cmd: Select) {
|
||||
}
|
||||
if (cmd.orderBy) {
|
||||
dmp.put('&n^order ^by ');
|
||||
dmp.putCollection(', ', cmd.orderBy, (expr) => {
|
||||
dmp.putCollection(', ', cmd.orderBy, expr => {
|
||||
dumpSqlExpression(dmp, expr);
|
||||
dmp.put(' %k', expr.direction);
|
||||
});
|
||||
@@ -67,7 +67,7 @@ export function dumpSqlUpdate(dmp: SqlDumper, cmd: Update) {
|
||||
|
||||
dmp.put('&n^set ');
|
||||
dmp.put('&>');
|
||||
dmp.putCollection(', ', cmd.fields, (col) => {
|
||||
dmp.putCollection(', ', cmd.fields, col => {
|
||||
dmp.put('%i=', col.targetColumn);
|
||||
dumpSqlExpression(dmp, col);
|
||||
});
|
||||
@@ -95,9 +95,9 @@ export function dumpSqlInsert(dmp: SqlDumper, cmd: Insert) {
|
||||
dmp.put(
|
||||
'^insert ^into %f (%,i) ^values (',
|
||||
cmd.targetTable,
|
||||
cmd.fields.map((x) => x.targetColumn)
|
||||
cmd.fields.map(x => x.targetColumn)
|
||||
);
|
||||
dmp.putCollection(',', cmd.fields, (x) => dumpSqlExpression(dmp, x));
|
||||
dmp.putCollection(',', cmd.fields, x => dumpSqlExpression(dmp, x));
|
||||
dmp.put(')');
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ export function dumpSqlCondition(dmp: SqlDumper, condition: Condition) {
|
||||
break;
|
||||
case 'and':
|
||||
case 'or':
|
||||
dmp.putCollection(` ^${condition.conditionType} `, condition.conditions, (cond) => {
|
||||
dmp.putCollection(` ^${condition.conditionType} `, condition.conditions, cond => {
|
||||
dmp.putRaw('(');
|
||||
dumpSqlCondition(dmp, cond);
|
||||
dmp.putRaw(')');
|
||||
|
||||
@@ -31,7 +31,7 @@ export function dumpSqlExpression(dmp: SqlDumper, expr: Expression) {
|
||||
case 'call':
|
||||
dmp.put('%s(', expr.func);
|
||||
if (expr.argsPrefix) dmp.put('%s ', expr.argsPrefix);
|
||||
dmp.putCollection(',', expr.args, (x) => dumpSqlExpression(dmp, x));
|
||||
dmp.putCollection(',', expr.args, x => dumpSqlExpression(dmp, x));
|
||||
dmp.put(')');
|
||||
break;
|
||||
|
||||
|
||||
@@ -44,12 +44,12 @@ export function dumpSqlRelation(dmp: SqlDumper, from: Relation) {
|
||||
dumpSqlSourceDef(dmp, from);
|
||||
if (from.conditions && from.conditions.length > 0) {
|
||||
dmp.put(' ^on ');
|
||||
dmp.putCollection(' ^and ', from.conditions, (cond) => dumpSqlCondition(dmp, cond));
|
||||
dmp.putCollection(' ^and ', from.conditions, cond => dumpSqlCondition(dmp, cond));
|
||||
}
|
||||
}
|
||||
|
||||
export function dumpSqlFromDefinition(dmp: SqlDumper, from: FromDefinition) {
|
||||
dumpSqlSourceDef(dmp, from);
|
||||
dmp.put(' ');
|
||||
if (from.relations) from.relations.forEach((rel) => dumpSqlRelation(dmp, rel));
|
||||
if (from.relations) from.relations.forEach(rel => dumpSqlRelation(dmp, rel));
|
||||
}
|
||||
|
||||
@@ -48,9 +48,9 @@ export function evaluateCondition(condition: Condition, values) {
|
||||
case 'isNotEmpty':
|
||||
return !isEmpty(evaluateExpression(condition.expr, values));
|
||||
case 'and':
|
||||
return condition.conditions.every((cond) => evaluateCondition(cond, values));
|
||||
return condition.conditions.every(cond => evaluateCondition(cond, values));
|
||||
case 'or':
|
||||
return condition.conditions.some((cond) => evaluateCondition(cond, values));
|
||||
return condition.conditions.some(cond => evaluateCondition(cond, values));
|
||||
case 'like':
|
||||
return isLike(evaluateExpression(condition.left, values), evaluateExpression(condition.right, values));
|
||||
break;
|
||||
|
||||
@@ -3,7 +3,7 @@ import _sortBy from 'lodash/sortBy';
|
||||
import _groupBy from 'lodash/groupBy';
|
||||
import _pick from 'lodash/pick';
|
||||
|
||||
const fp_pick = (arg) => (array) => _pick(array, arg);
|
||||
const fp_pick = arg => array => _pick(array, arg);
|
||||
export class DatabaseAnalyser {
|
||||
structure: DatabaseInfo;
|
||||
modifications: DatabaseModification[];
|
||||
@@ -51,14 +51,14 @@ export class DatabaseAnalyser {
|
||||
const res = {};
|
||||
for (const field of ['tables', 'views', 'functions', 'procedures', 'triggers']) {
|
||||
const removedIds = this.modifications
|
||||
.filter((x) => x.action == 'remove' && x.objectTypeField == field)
|
||||
.map((x) => extractObjectId(x));
|
||||
.filter(x => x.action == 'remove' && x.objectTypeField == field)
|
||||
.map(x => extractObjectId(x));
|
||||
const newArray = newlyAnalysed[field] || [];
|
||||
const addedChangedIds = newArray.map((x) => extractObjectId(x));
|
||||
const addedChangedIds = newArray.map(x => extractObjectId(x));
|
||||
const removeAllIds = [...removedIds, ...addedChangedIds];
|
||||
res[field] = _sortBy(
|
||||
[...this.structure[field].filter((x) => !removeAllIds.includes(extractObjectId(x))), ...newArray],
|
||||
(x) => x.pureName
|
||||
[...this.structure[field].filter(x => !removeAllIds.includes(extractObjectId(x))), ...newArray],
|
||||
x => x.pureName
|
||||
);
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ export class DatabaseAnalyser {
|
||||
}
|
||||
|
||||
static byTableFilter(table) {
|
||||
return (x) => x.pureName == table.pureName && x.schemaName == x.schemaName;
|
||||
return x => x.pureName == table.pureName && x.schemaName == x.schemaName;
|
||||
}
|
||||
|
||||
static extractPrimaryKeys(table, pkColumns) {
|
||||
@@ -101,7 +101,7 @@ export class DatabaseAnalyser {
|
||||
}
|
||||
static extractForeignKeys(table, fkColumns) {
|
||||
const grouped = _groupBy(fkColumns.filter(DatabaseAnalyser.byTableFilter(table)), 'constraintName');
|
||||
return Object.keys(grouped).map((constraintName) => ({
|
||||
return Object.keys(grouped).map(constraintName => ({
|
||||
constraintName,
|
||||
constraintType: 'foreignKey',
|
||||
..._pick(grouped[constraintName][0], [
|
||||
|
||||
@@ -7,9 +7,9 @@ import {
|
||||
TableInfo,
|
||||
TransformType,
|
||||
} from 'dbgate-types';
|
||||
import _isString from 'lodash/isString'
|
||||
import _isNumber from 'lodash/isNumber'
|
||||
import _isDate from 'lodash/isDate'
|
||||
import _isString from 'lodash/isString';
|
||||
import _isNumber from 'lodash/isNumber';
|
||||
import _isDate from 'lodash/isDate';
|
||||
|
||||
export class SqlDumper {
|
||||
s = '';
|
||||
@@ -95,7 +95,7 @@ export class SqlDumper {
|
||||
}
|
||||
putFormattedList(c, collection) {
|
||||
if (!collection) return;
|
||||
this.putCollection(', ', collection, (item) => this.putFormattedValue(c, item));
|
||||
this.putCollection(', ', collection, item => this.putFormattedValue(c, item));
|
||||
}
|
||||
put(format: string, ...args) {
|
||||
let i = 0;
|
||||
@@ -203,7 +203,7 @@ export class SqlDumper {
|
||||
|
||||
createTable(table: TableInfo) {
|
||||
this.put('^create ^table %f ( &>&n', table);
|
||||
this.putCollection(',&n', table.columns, (col) => {
|
||||
this.putCollection(',&n', table.columns, col => {
|
||||
this.put('%i ', col.columnName);
|
||||
this.columnDefinition(col);
|
||||
});
|
||||
@@ -214,11 +214,11 @@ export class SqlDumper {
|
||||
}
|
||||
this.put(
|
||||
' ^primary ^key (%,i)',
|
||||
table.primaryKey.columns.map((x) => x.columnName)
|
||||
table.primaryKey.columns.map(x => x.columnName)
|
||||
);
|
||||
}
|
||||
if (table.foreignKeys) {
|
||||
table.foreignKeys.forEach((fk) => {
|
||||
table.foreignKeys.forEach(fk => {
|
||||
this.put(',&n');
|
||||
this.createForeignKeyFore(fk);
|
||||
});
|
||||
@@ -247,9 +247,9 @@ export class SqlDumper {
|
||||
if (fk.constraintName != null) this.put('^constraint %i ', fk.constraintName);
|
||||
this.put(
|
||||
'^foreign ^key (%,i) ^references %f (%,i)',
|
||||
fk.columns.map((x) => x.columnName),
|
||||
fk.columns.map(x => x.columnName),
|
||||
{ schemaName: fk.refSchemaName, pureName: fk.refTableName },
|
||||
fk.columns.map((x) => x.refColumnName)
|
||||
fk.columns.map(x => x.refColumnName)
|
||||
);
|
||||
if (fk.deleteAction) this.put(' ^on ^delete %k', fk.deleteAction);
|
||||
if (fk.updateAction) this.put(' ^on ^update %k', fk.updateAction);
|
||||
|
||||
@@ -15,7 +15,7 @@ export function createBulkInsertStreamBase(driver, stream, pool, name, options):
|
||||
writable.structure = null;
|
||||
writable.columnNames = null;
|
||||
|
||||
writable.addRow = async (row) => {
|
||||
writable.addRow = async row => {
|
||||
if (writable.structure) {
|
||||
writable.buffer.push(row);
|
||||
} else {
|
||||
@@ -44,8 +44,8 @@ export function createBulkInsertStreamBase(driver, stream, pool, name, options):
|
||||
}
|
||||
|
||||
writable.columnNames = _intersection(
|
||||
structure.columns.map((x) => x.columnName),
|
||||
writable.structure.columns.map((x) => x.columnName)
|
||||
structure.columns.map(x => x.columnName),
|
||||
writable.structure.columns.map(x => x.columnName)
|
||||
);
|
||||
};
|
||||
|
||||
@@ -56,14 +56,14 @@ export function createBulkInsertStreamBase(driver, stream, pool, name, options):
|
||||
const dmp = driver.createDumper();
|
||||
|
||||
dmp.putRaw(`INSERT INTO ${fullNameQuoted} (`);
|
||||
dmp.putCollection(',', writable.columnNames, (col) => dmp.putRaw(driver.dialect.quoteIdentifier(col)));
|
||||
dmp.putCollection(',', writable.columnNames, col => dmp.putRaw(driver.dialect.quoteIdentifier(col)));
|
||||
dmp.putRaw(')\n VALUES\n');
|
||||
|
||||
let wasRow = false;
|
||||
for (const row of rows) {
|
||||
if (wasRow) dmp.putRaw(',\n');
|
||||
dmp.putRaw('(');
|
||||
dmp.putCollection(',', writable.columnNames, (col) => dmp.putValue(row[col]));
|
||||
dmp.putCollection(',', writable.columnNames, col => dmp.putValue(row[col]));
|
||||
dmp.putRaw(')');
|
||||
wasRow = true;
|
||||
}
|
||||
@@ -84,7 +84,7 @@ export function createBulkInsertStreamBase(driver, stream, pool, name, options):
|
||||
callback();
|
||||
};
|
||||
|
||||
writable._final = async (callback) => {
|
||||
writable._final = async callback => {
|
||||
await writable.send();
|
||||
callback();
|
||||
};
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { SqlDumper } from "./SqlDumper";
|
||||
import { SqlDumper } from './SqlDumper';
|
||||
|
||||
const dialect = {
|
||||
limitSelect: true,
|
||||
|
||||
@@ -39,13 +39,13 @@ export function findObjectLike(
|
||||
if (schemaName) {
|
||||
// @ts-ignore
|
||||
return dbinfo[objectTypeField].find(
|
||||
(x) => equalStringLike(x.pureName, pureName) && equalStringLike(x.schemaName, schemaName)
|
||||
x => equalStringLike(x.pureName, pureName) && equalStringLike(x.schemaName, schemaName)
|
||||
);
|
||||
}
|
||||
// @ts-ignore
|
||||
return dbinfo[objectTypeField].find((x) => equalStringLike(x.pureName, pureName));
|
||||
return dbinfo[objectTypeField].find(x => equalStringLike(x.pureName, pureName));
|
||||
}
|
||||
|
||||
export function findForeignKeyForColumn(table: TableInfo, column: ColumnInfo) {
|
||||
return (table.foreignKeys || []).find((fk) => fk.columns.find((col) => col.columnName == column.columnName));
|
||||
return (table.foreignKeys || []).find(fk => fk.columns.find(col => col.columnName == column.columnName));
|
||||
}
|
||||
|
||||
@@ -37,12 +37,12 @@ export function extractShellApiFunctionName(functionName) {
|
||||
|
||||
export function findEngineDriver(connection, extensions: ExtensionsDirectory): EngineDriver {
|
||||
if (_isString(connection)) {
|
||||
return extensions.drivers.find((x) => x.engine == connection);
|
||||
return extensions.drivers.find(x => x.engine == connection);
|
||||
}
|
||||
if (_isPlainObject(connection)) {
|
||||
const { engine } = connection;
|
||||
if (engine) {
|
||||
return extensions.drivers.find((x) => x.engine == engine);
|
||||
return extensions.drivers.find(x => x.engine == engine);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -288,5 +288,5 @@ export function splitPostgresQuery(sql: string, options?: SplitOptions): string[
|
||||
}
|
||||
} while (context.unread !== '');
|
||||
publishStatement(context);
|
||||
return context.output.map((v) => v.value);
|
||||
return context.output.map(v => v.value);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import _isString from 'lodash/isString';
|
||||
export function compilePermissions(permissions: string[] | string) {
|
||||
if (!permissions) return null;
|
||||
if (_isString(permissions)) permissions = permissions.split(',');
|
||||
return permissions.map((x) => new RegExp('^' + _escapeRegExp(x).replace(/\\\*/g, '.*') + '$'));
|
||||
return permissions.map(x => new RegExp('^' + _escapeRegExp(x).replace(/\\\*/g, '.*') + '$'));
|
||||
}
|
||||
|
||||
export function testPermission(tested: string, permissions: RegExp[]) {
|
||||
|
||||
Reference in New Issue
Block a user