Dellgenius
Explore posts from serversDTDrizzle 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:
This results in a response like this:
Desired Output:
I want to structure the JSON to group order_lines
and items
under each order
:
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!4 replies
DTDrizzle Team
•Created by Dellgenius on 4/28/2024 in #help
db.select returning [], but a directly executed neon sql statement returns data.
Hi, here is my code.
export const getData = async () => {
console.log("neon", await sql_neon
SELECT * FROM todo WHERE id = ${1});
console.log("drizzle", await db.select().from(todo));
};
Here is the console output on the server:
neon [ { id: 1, text: 'asdf', done: true } ]
Query: select "id", "text", "done" from "todo"
drizzle []
The second line is from the drizzle debugger. I'm really confused about what's going on. I am using the default code from the nextjs neon todo from the docs. I can successfully insert, but can't select anything. I've been left scratching my head and have no clue why this is happening. Thanks for any help.1 replies
DTDrizzle Team
•Created by Dellgenius on 4/28/2024 in #help
Error: No database connection string was provided to `neon()`.
Hi.
Here is my code:
import { neon } from "@neondatabase/serverless";
import "dotenv/config";
import { drizzle } from "drizzle-orm/neon-http";
const sql = neon(process.env.NEON_DATABASE_URL!);
const db = drizzle(sql);
export default db;
I get the following error:
Error: No database connection string was provided to
neon(). Perhaps an environment variable has not been set?
I have tried hard coding in the string, and it works. I am not sure what's going on, since if I console log the connection string, it shows up just fine in the server log. I tried the solutions here by to no avail:
https://discord.com/channels/1043890932593987624/1203696288177070140
Would appreciate any advice!1 replies