DTDrizzle Team
Created by Dellgenius on 5/1/2024 in #help
How can I get a better structured response when querying a table (many to many)?
Hi, I am new to sql. This might be obvious, but I'm not sure how to go about this. Below is a simplified example of what I hope to achieve. I have three tables: orders, order_lines, and items. order_lines is a junction table. Here's how I'm currently fetching the data:
const ordersWithItems = await db.select().from(orders)
.leftJoin(order_lines, eq(order_lines.order_id, orders.xata_id))
.leftJoin(items, eq(items.xata_id, order_lines.item_id));
const ordersWithItems = await db.select().from(orders)
.leftJoin(order_lines, eq(order_lines.order_id, orders.xata_id))
.leftJoin(items, eq(items.xata_id, order_lines.item_id));
This results in a response like this:
[
{
"order_id": "order1",
"order_date": "2024-04-01",
"line_id": "line1",
"item_id": "item1",
"item_price": "1000"
},
{
"order_id": "order1",
"order_date": "2024-04-01",
"line_id": "line2",
"item_id": "item2",
"item_price": "50"
}
]
[
{
"order_id": "order1",
"order_date": "2024-04-01",
"line_id": "line1",
"item_id": "item1",
"item_price": "1000"
},
{
"order_id": "order1",
"order_date": "2024-04-01",
"line_id": "line2",
"item_id": "item2",
"item_price": "50"
}
]
Desired Output: I want to structure the JSON to group order_lines and items under each order:
[
{
"order_id": "order1",
"order_date": "2024-04-01",
"lines": [
{
"line_id": "line1",
"price": "1000",
"item": {
"id": "item1",
"name": "Laptop",
}
},
{
"line_id": "line2",
"price": "50",
"item": {
"id": "item2",
"name": "Mouse",
}
}
]
}
]
[
{
"order_id": "order1",
"order_date": "2024-04-01",
"lines": [
{
"line_id": "line1",
"price": "1000",
"item": {
"id": "item1",
"name": "Laptop",
}
},
{
"line_id": "line2",
"price": "50",
"item": {
"id": "item2",
"name": "Mouse",
}
}
]
}
]
Is there a way to to do this natively with drizzle, or do I need to manually process the results after fetching them? Would appreciate any help!
1 replies
DHDistant Horizons
Created by El Dorado on 5/1/2024 in #bug-report
"distant horizons has encountered an exception"
No description
2 replies
BRBuildShip + Rowy
Created by Abrar on 5/1/2024 in #❓・buildship-help
Validating the existence of query string parameters
So I'm relaying a call to an api which accepts a bunch of optional query params.... When i make the API call... I try to pass on the query params like so...
{
"key" : (await getSecret("openaustralia-key")),
"date" : ctx["root"]["request"]["query"].date,
"party" : ctx["root"]["request"]["query"].party,
"state" : ctx["root"]["request"]["query"].state,
"search" : ctx["root"]["request"]["query"].search
}
{
"key" : (await getSecret("openaustralia-key")),
"date" : ctx["root"]["request"]["query"].date,
"party" : ctx["root"]["request"]["query"].party,
"state" : ctx["root"]["request"]["query"].state,
"search" : ctx["root"]["request"]["query"].search
}
I'm looking for a simple in-line way to validate the existence of each param, and only then and only populate the value.. Does anyone know how to do this in a clean and efficient manner? (NB: im not a javascript guru) Thanks in advance
2 replies
VVALORANT
Created by 𝕭𝕿𝕮 on 5/1/2024 in #community-help
When is the new battlepass coming out ?
Help
17 replies
VVALORANT
Created by Yayo on 5/1/2024 in #community-help
Secure boot enabled not allowing me to play
No description
1 replies
HHono
Created by Franz3 on 5/1/2024 in #help
Failed to load .env file ".env": Error: ENOENT: no such file or directory
Hey, Im new to using cloudflare and new to using Hono. I now came across an error that tells me Im missing a .env file, which also should contain some variables. The problem is, idk where I use these and what their values should be. It seems like these should be using system variables instead (Im currently on Windows 10), but I could find an answer online. This only started appearing after I added and tried using Hono. Here is my code:
import { Hono } from "hono";
import { testFeed } from "./createRssFeed";

const app = new Hono();

app.get("/", async content => {
content.header("Content-Type", "application/atom+xml");
content.header("Cache-Control", "no-cache");

const feed = testFeed();
return content.body(feed);
});
export default app;
import { Hono } from "hono";
import { testFeed } from "./createRssFeed";

const app = new Hono();

app.get("/", async content => {
content.header("Content-Type", "application/atom+xml");
content.header("Cache-Control", "no-cache");

const feed = testFeed();
return content.body(feed);
});
export default app;
The wrangler.toml file:
name = "qmj-atom-feed"
main = "src/index.ts"
compatibility_date = "2024-04-19"
compatibility_flags = ["nodejs_compat"]
name = "qmj-atom-feed"
main = "src/index.ts"
compatibility_date = "2024-04-19"
compatibility_flags = ["nodejs_compat"]
5 replies
AAAndronix App
Created by MATRIX on 5/1/2024 in #support-forum
can't open any site on firefox
Hello I recently installed a modified version of Ubuntu on my system. Initially, I encountered an issue with VS Code, which I managed to resolve. However, I'm now facing difficulties with my browser; it's unable to open any websites. Could someone please assist me with troubleshooting this problem? #support
2 replies
VVALORANT
Created by MIDGAMER🇺🇸 on 5/1/2024 in #community-help
change region problem
I contact support and they tell me to login consecutive 14days but my friend change region and takes only a day i dont know why
2 replies
DHDistant Horizons
Created by El Dorado on 5/1/2024 in #bug-report
supah tall LOD chunks
No description
8 replies
CDCloudflare Developers
Created by w3bcode on 5/1/2024 in #general-help
How to add custom hostname for multi tenant application with cloudflare pages ?
No description
1 replies
Mmalefashionadvice
Created by evan on 5/1/2024 in #questions-and-advice
Any similar shirt that actually ships to the US?
1 replies
CC#
Created by Mist on 5/1/2024 in #help
Program csv extraction
No description
5 replies
VVALORANT
Created by ᗪIG1♰4ᒪ on 5/1/2024 in #community-help
Valorant Freezing
For some reason my game keeps freezing when the game ends and returning to lobby and i have to restart my pc eveyrtime to play another match any fixes?
2 replies
VVALORANT
Created by evan on 5/1/2024 in #community-help
crosshairs
all my crosshairs got deleted and i only have default one?
2 replies
VVALORANT
Created by pienter post on 5/1/2024 in #community-help
cards and title
how do I get the radiant confirmed 100 accuracy player card or the aimbot title?
2 replies
RRCRat Rig Community [Unofficial]
Created by F1sH on 5/1/2024 in #ratos-support
Beacon Move Out of Range
No description
2 replies
VVALORANT
Created by arzxm on 5/1/2024 in #community-help
my cross hairs got reset
Help how I change back I had super cool cross hairs now it'd all gone
2 replies
VVALORANT
Created by Blepz on 5/1/2024 in #community-help
Very Low Fps
I am so confused, I use to fun 144fps perfectly now its like 5fps max, I have a 4070 with 16gigs of ram and was running the game perfectly up until now for no reason. Game is set to high priority so I have no clue on why its like 5 fps
3 replies