This commit is contained in:
Rizky 2024-06-25 02:05:58 -07:00
parent aba7764107
commit a37399adfa
3 changed files with 25 additions and 22 deletions

View File

@ -51,7 +51,7 @@ async (arg: TableOnLoad) => {
const items = await db.${table}.findMany({ const items = await db.${table}.findMany({
select: ${JSON.stringify(select, null, 2).split("\n").join("\n ")}, select: ${JSON.stringify(select, null, 2).split("\n").join("\n ")},
orderBy: arg.orderBy || { orderBy: arg.orderBy || {
id: "desc", ${pk}: "desc",
}, },
where: { where: {
...where, ...where,

View File

@ -86,27 +86,29 @@ const get_layer = async (
if (current < depth) { if (current < depth) {
if (rels) { if (rels) {
for (const [k, v] of Object.entries(rels)) { for (const [k, v] of Object.entries(rels)) {
const to = v.to; if (v?.to && v?.from) {
const from = v.from; const to = v.to;
const r_rels = (await get_layer( const from = v.from;
id_site, const r_rels = (await get_layer(
depth, id_site,
current + 1, depth,
arg, current + 1,
v.to.table arg,
)) as any; v.to.table
options.push({ )) as any;
value: JSON.stringify({ options.push({
name: k, value: JSON.stringify({
is_pk: false, name: k,
type: v.type, is_pk: false,
optional: true, type: v.type,
relation: { from, to }, optional: true,
}), relation: { from, to },
label: k, }),
options: r_rels, label: k,
checked: false, options: r_rels,
}); checked: false,
});
}
} }
} }
} }

View File

@ -5,6 +5,7 @@ export const gen_props_table = async () => {
if (cache.length > 0) return cache; if (cache.length > 0) return cache;
const tables = await db._schema.tables(); const tables = await db._schema.tables();
console.log(tables);
if (!Array.isArray(tables)) { if (!Array.isArray(tables)) {
alert("WARNING: failed to get tables from app server"); alert("WARNING: failed to get tables from app server");
return []; return [];