This commit is contained in:
Rizky 2024-03-24 13:52:56 +07:00
parent 80db2618fc
commit c6849b3aac
1 changed files with 31 additions and 24 deletions

View File

@ -1,4 +1,4 @@
import { createPrismaSchemaBuilder } from "@mrleebo/prisma-ast"; import { Attribute, createPrismaSchemaBuilder } from "@mrleebo/prisma-ast";
import { readAsync } from "fs-jetpack"; import { readAsync } from "fs-jetpack";
import { Prisma } from "../../app/db/db"; import { Prisma } from "../../app/db/db";
import { dir } from "./dir"; import { dir } from "./dir";
@ -147,33 +147,40 @@ export const execQuery = async (args: DBArg, prisma: any) => {
} }
return rels; return rels;
} else if (action === "schema_columns") { } else if (action === "schema_columns") {
console.log(schema_table.properties);
for (const col of schema_table.properties) { for (const col of schema_table.properties) {
if ( if (col.type === "field" && !col.array) {
col.type === "field" && let is_pk = false;
!col.array && let type = col.fieldType;
col.attributes && let attr = undefined as Attribute | undefined;
col.attributes?.length > 0 let default_val = undefined as Attribute | undefined;
) { if (col.attributes && col.attributes?.length > 0) {
const attr = col.attributes.find( attr = col.attributes.find(
(e) => e.name !== "id" && e.name !== "default" (e) => e.name !== "id" && e.name !== "default"
); );
const default_val = col.attributes.find( default_val = col.attributes.find((e) => e.name === "default");
(e) => e.name === "default" is_pk = !!col.attributes.find((e) => e.name === "id");
);
const is_pk = col.attributes.find((e) => e.name === "id");
if (attr && attr.name !== "relation") { 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;
}
}
columns[col.name] = { if (typeof type === "string") {
is_pk: !!is_pk, const db_type = attr
type: type.toLowerCase(), ? attr.name.toLowerCase()
optional: !!col.optional, : type.toLowerCase();
db_type: attr.name.toLowerCase(), if (db_type !== "relation") {
default: default_val, columns[col.name] = {
}; is_pk: !!is_pk,
type: type.toLowerCase(),
optional: !!col.optional,
db_type,
default: default_val,
};
}
} }
} }
} }