get table definition
This commit is contained in:
parent
717de68f4e
commit
9944fb931a
2 changed files with 40 additions and 5 deletions
34
src/helpers/dynamicQueryBuilder.ts
Normal file
34
src/helpers/dynamicQueryBuilder.ts
Normal file
|
@ -0,0 +1,34 @@
|
|||
import { dataSource } from "../data-source";
|
||||
import { DynamicQueryStructure } from "../type/dynamicQueries";
|
||||
|
||||
export default abstract class DynamicQueryBuilder {
|
||||
public static buildQuery(query: DynamicQueryStructure) {}
|
||||
|
||||
// use switch... for compare functions
|
||||
// use NotBrackets/Brackets for nested conditions
|
||||
// use joins by requesting table schema and setting correct column
|
||||
|
||||
public static getTableMeta(tableName: string) {
|
||||
let { name, columns, relations } = dataSource.getMetadata(tableName);
|
||||
|
||||
const uniqueColumns = columns.map((c) => ({ column: c.propertyName, type: c.type }));
|
||||
|
||||
return {
|
||||
tableName: name,
|
||||
columns: [
|
||||
...uniqueColumns,
|
||||
...relations
|
||||
.filter((r) => !uniqueColumns.some((c) => r.propertyName == c.column))
|
||||
.map((r) => ({
|
||||
column: r.propertyName,
|
||||
type: r.inverseEntityMetadata?.columns.find((col) => col.propertyName === r.inverseSidePropertyPath)?.type,
|
||||
})),
|
||||
],
|
||||
relations: relations.map((r) => ({
|
||||
column: r.propertyName,
|
||||
relationType: r.relationType,
|
||||
referencedTableName: r.inverseEntityMetadata?.tableName,
|
||||
})),
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue