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