Relational queries (PlanetScale)

Hi, does drizzle-orm/mysql2 support relational queries? I am currently using PlanetScale, but I haven't been able to find any information about relational queries in the following documents: - https://orm.drizzle.team/docs/rqb - https://github.com/drizzle-team/drizzle-orm/blob/main/drizzle-orm/src/mysql-core/README.md - https://github.com/planetscale/database-js Ideally, I would like a developer-friendly response like this:
[
id: 10,
name: "Dan",
posts: [
{
id: 1,
content: "SQL is awesome",
authorId: 10,
},
{
id: 2,
content: "But check relational queries",
authorId: 10,
}
]
[
id: 10,
name: "Dan",
posts: [
{
id: 1,
content: "SQL is awesome",
authorId: 10,
},
{
id: 2,
content: "But check relational queries",
authorId: 10,
}
]
...as opposed to a response like this:
[
{
id: 10,
name: "Dan",
posts: {
id: 1,
content: "SQL is awesome",
authorId: 10,
}
},
{
id: 10,
name: "Dan",
posts: {
id: 2,
content: "But check relational queries",
authorId: 10,
}
}
]
[
{
id: 10,
name: "Dan",
posts: {
id: 1,
content: "SQL is awesome",
authorId: 10,
}
},
{
id: 10,
name: "Dan",
posts: {
id: 2,
content: "But check relational queries",
authorId: 10,
}
}
]
If there is any workaround for this situation, without having to use relational queries, I would greatly appreciate it if you could let me know. Thank you for your time.
GitHub
drizzle-orm/README.md at main · drizzle-team/drizzle-orm
TypeScript ORM that feels like writing SQL. Contribute to drizzle-team/drizzle-orm development by creating an account on GitHub.
GitHub
GitHub - planetscale/database-js: A Fetch API-compatible PlanetScal...
A Fetch API-compatible PlanetScale database driver - GitHub - planetscale/database-js: A Fetch API-compatible PlanetScale database driver
5 Replies
Andrii Sherman
Andrii Sherman•2y ago
You can use a custom aggregation logic
Hayato
HayatoOP•2y ago
Hello, thank you for your response. I've examined the link you provided, and it appears to be primarily concerned with output formatting. From what I understand, currently, Drizzle requires an additional step to produce user-friendly outputs in MySQL compared to Prisma. I'm currently using Vercel at the edge and specifically targeting the Tokyo region, hence I've been seeking a suitable database for this setup. PlanetScale, with its Tokyo region availability, was appealing to me. However, considering the support for relational queries, I'm also exploring PostgreSQL databases like Supabase, which likewise offers a Tokyo region. I appreciate your assistance in clarifying this situation.
Dan
Dan•2y ago
does drizzle-orm/mysql2 support relational queries?
it does what made you think it doesn't? all three dialects (Postgres, MySQL, SQLite) support relational queries
Hayato
HayatoOP•2y ago
@Dan Kochetov Thank you for your response. I have tried using relational queries with PlanetScale, and it worked!!! 🙂 I created a GitHub repository for anyone who might have the same questions regarding the use of relational queries with PlanetScale. https://github.com/hayato94087/nextjs-planetscale-drizzle-20230609-test The main problem I encountered was forgetting to include {schema} as a parameter in drizzle.
const db = drizzle(connection, { schema });
const db = drizzle(connection, { schema });
Thank you for your time.
GitHub
GitHub - hayato94087/nextjs-planetscale-drizzle-20230609-test
Contribute to hayato94087/nextjs-planetscale-drizzle-20230609-test development by creating an account on GitHub.
Want results from more Discord servers?
Add your server