fix query
This commit is contained in:
parent
0f828bccce
commit
96dbca0e55
|
|
@ -228,7 +228,15 @@ export const execQuery = async (args: DBArg, prisma: any) => {
|
||||||
const view = schema.findAllByType("view", {}).map((e) => e?.name);
|
const view = schema.findAllByType("view", {}).map((e) => e?.name);
|
||||||
return [...tables, ...view];
|
return [...tables, ...view];
|
||||||
} else {
|
} else {
|
||||||
const schema_table = schema.findByType("model", { name: table });
|
let schema_table = schema.findByType("model", { name: table });
|
||||||
|
let is_view = false;
|
||||||
|
if (!schema_table) {
|
||||||
|
const view = schema.findByType("view", { name: table });
|
||||||
|
if (view) {
|
||||||
|
is_view = true;
|
||||||
|
schema_table = view as any;
|
||||||
|
}
|
||||||
|
}
|
||||||
const columns = {} as Record<
|
const columns = {} as Record<
|
||||||
string,
|
string,
|
||||||
{
|
{
|
||||||
|
|
@ -257,19 +265,22 @@ export const execQuery = async (args: DBArg, prisma: any) => {
|
||||||
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");
|
let is_pk = col.attributes.find((e) => e.name === "id");
|
||||||
|
|
||||||
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) {
|
if ((attr && attr.name !== "relation") || !attr) {
|
||||||
|
const db_type = attr
|
||||||
|
? attr.name.toLowerCase()
|
||||||
|
: type.toLowerCase();
|
||||||
|
if (is_view && db_type === "unique") is_pk = true as any;
|
||||||
|
|
||||||
columns[col.name] = {
|
columns[col.name] = {
|
||||||
is_pk: !!is_pk,
|
is_pk: !!is_pk,
|
||||||
type: type.toLowerCase(),
|
type: type.toLowerCase(),
|
||||||
optional: !!col.optional,
|
optional: !!col.optional,
|
||||||
db_type: attr
|
db_type,
|
||||||
? attr.name.toLowerCase()
|
|
||||||
: type.toLowerCase(),
|
|
||||||
default: default_val,
|
default: default_val,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue