mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-22 20:26:00 +00:00
perspective defaults - FK columns
This commit is contained in:
@@ -12,6 +12,7 @@
|
|||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"dbgate-sqltree": "^5.0.0-alpha.1",
|
"dbgate-sqltree": "^5.0.0-alpha.1",
|
||||||
|
"dbgate-tools": "^5.0.0-alpha.1",
|
||||||
"dbgate-filterparser": "^5.0.0-alpha.1"
|
"dbgate-filterparser": "^5.0.0-alpha.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { findForeignKeyForColumn } from 'dbgate-tools';
|
||||||
import { DatabaseInfo, TableInfo } from 'dbgate-types';
|
import { DatabaseInfo, TableInfo } from 'dbgate-types';
|
||||||
|
|
||||||
export function getPerspectiveDefaultColumns(table: TableInfo, db: DatabaseInfo): string[] {
|
export function getPerspectiveDefaultColumns(table: TableInfo, db: DatabaseInfo): string[] {
|
||||||
@@ -8,6 +9,7 @@ export function getPerspectiveDefaultColumns(table: TableInfo, db: DatabaseInfo)
|
|||||||
x => x.toLowerCase().includes('name'),
|
x => x.toLowerCase().includes('name'),
|
||||||
x => x.toLowerCase().includes('title'),
|
x => x.toLowerCase().includes('title'),
|
||||||
x => x.dataType?.toLowerCase()?.includes('char'),
|
x => x.dataType?.toLowerCase()?.includes('char'),
|
||||||
|
x => findForeignKeyForColumn(table, x)?.columns?.length == 1,
|
||||||
];
|
];
|
||||||
|
|
||||||
for (const predicate of predicates) {
|
for (const predicate of predicates) {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import _ from 'lodash';
|
import _cloneDeep from 'lodash/cloneDeep';
|
||||||
|
import _isString from 'lodash/isString';
|
||||||
import { ColumnInfo, ColumnReference, DatabaseInfo, DatabaseInfoObjects, SqlDialect, TableInfo } from 'dbgate-types';
|
import { ColumnInfo, ColumnReference, DatabaseInfo, DatabaseInfoObjects, SqlDialect, TableInfo } from 'dbgate-types';
|
||||||
|
|
||||||
export function fullNameFromString(name) {
|
export function fullNameFromString(name) {
|
||||||
@@ -54,7 +55,10 @@ export function findObjectLike(
|
|||||||
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 | string) {
|
||||||
|
if (_isString(column)) {
|
||||||
|
return (table.foreignKeys || []).find(fk => fk.columns.find(col => col.columnName == column));
|
||||||
|
}
|
||||||
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,7 +80,7 @@ function columnsConstraintName(prefix: string, table: TableInfo, columns: Column
|
|||||||
|
|
||||||
export function fillConstraintNames(table: TableInfo, dialect: SqlDialect) {
|
export function fillConstraintNames(table: TableInfo, dialect: SqlDialect) {
|
||||||
if (!table) return table;
|
if (!table) return table;
|
||||||
const res = _.cloneDeep(table);
|
const res = _cloneDeep(table);
|
||||||
if (res.primaryKey && !res.primaryKey.constraintName && !dialect.anonymousPrimaryKey) {
|
if (res.primaryKey && !res.primaryKey.constraintName && !dialect.anonymousPrimaryKey) {
|
||||||
res.primaryKey.constraintName = `PK_${res.pureName}`;
|
res.primaryKey.constraintName = `PK_${res.pureName}`;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user