This commit is contained in:
Rizky 2024-04-20 15:07:37 +07:00
parent ef4c14cb8f
commit 9771281430
1 changed files with 25 additions and 18 deletions

View File

@ -151,31 +151,38 @@ export const execQuery = async (args: DBArg, prisma: any) => {
return rels; return rels;
} else if (action === "schema_columns") { } else if (action === "schema_columns") {
for (const col of schema_table.properties) { for (const col of schema_table.properties) {
if ( if (col.type === "field" && !col.array) {
col.type === "field" && if (col.attributes && col.attributes?.length > 0) {
!col.array && const attr = col.attributes.find(
col.attributes && (e) => e.name !== "id" && e.name !== "default"
col.attributes?.length > 0 );
) {
const attr = col.attributes.find(
(e) => e.name !== "id" && e.name !== "default"
);
const default_val = col.attributes.find( const default_val = col.attributes.find(
(e) => e.name === "default" (e) => e.name === "default"
); );
const is_pk = col.attributes.find((e) => e.name === "id"); const is_pk = col.attributes.find((e) => e.name === "id");
if (attr && attr.name !== "relation") {
let type = "String"; let type = "String";
if (typeof col.fieldType === "string") type = col.fieldType; if (typeof col.fieldType === "string") type = col.fieldType;
if ((attr && attr.name !== "relation") || !attr) {
columns[col.name] = {
is_pk: !!is_pk,
type: type.toLowerCase(),
optional: !!col.optional,
db_type: attr
? attr.name.toLowerCase()
: type.toLowerCase(),
default: default_val,
};
}
} else if (typeof col.fieldType === "string") {
columns[col.name] = { columns[col.name] = {
is_pk: !!is_pk, is_pk: false,
type: type.toLowerCase(), type: col.fieldType.toLowerCase(),
optional: !!col.optional, optional: !!col.optional,
db_type: attr.name.toLowerCase(), db_type: col.fieldType.toLowerCase(),
default: default_val, default: null,
}; };
} }
} }