Closed elberthomay closed 3 months ago
Hello, I'm trying out query returning nested object
const result = await db .selectFrom("User") .selectAll("User") .innerJoin("Shop", "Shop.userId", "User.id") .select((eb) => [ "Shop.id as shopId", "Shop.name as shopName", jsonArrayFrom( eb .selectFrom("Item") .select((eb) => [ "Item.id", "Item.name", "Item.price", eb.fn .agg<number>("row_number") .over((ob) => ob.orderBy("Item.name", "desc")) .as("num"), jsonArrayFrom( eb .selectFrom("ItemImages") .select([ eb.fn .agg<number>("row_number") .over((ob: any) => ob.orderBy("ItemImages.order")) .as("num"), "ItemImages.imageName", "ItemImages.order", "ItemImages.createdAt", ]) .whereRef("ItemImages.itemId", "=", "Item.id") ).as("images"), ]) .whereRef("Item.shopId", "=", "Shop.id") .limit(10) ).as("items"), ]) .forUpdate() .execute();
It works great, orderBy doesn't work so i'm using row_number with over, but that leaves the num property in the result, is there a way to exclude certain property in jsonArrayFrom?
There's nothing built-in that'd help here.
Hello, I'm trying out query returning nested object
It works great, orderBy doesn't work so i'm using row_number with over, but that leaves the num property in the result, is there a way to exclude certain property in jsonArrayFrom?