DT
Drizzle Teamnr7751
( sql question ) How do you join full tables with select columns from other table?
Hi everyone. I'm new to Drizzle. I have this TypeScript function:
I realize this is a basic SQL question. This is currently returning one object of services and another of serviceProfiles per entry in the services table. Bear in mind there is one serviceProfile per services entry, in a one-to-one relationship.
Instead of two separate objects per each entry of services table, how can I return a single object with all entries of services table plus select columns from serviceProfiles table, all merged into a single object per services table entry?
Thanks in advance!
Solution
arily•16d ago
select({id: services.id, …}).from(…).innerJoin(…)
nr7751•16d ago
@arily , it worked!
```typescript
export const fetchAllServicesWithProfiles = async () => {
const result = await db
.select({
id: services.id,
category: services.category,
service: services.service,
description: services.description,
unit: services.unit,
duration: services.duration,
personnel: services.personnel,
included: services.included,
price: serviceProfiles.price,
sale: serviceProfiles.sale,
saleExpiresBy: serviceProfiles.saleExpiresBy,
popularity: serviceProfiles.popularity,
})
.from(services)
.innerJoin(serviceProfiles, eq(services.id, serviceProfiles.serviceId));
return result;
};
Thanks a bunch!
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
7.4KMembers
View on DiscordWant results from more Discord servers?
More PostsCannot migrate/push after adding column to sqlite tableI'm new to Drizzle, so I assume I'm just doing things wrong.
I have a sqlite db with a bunch of tablHelp building queries based on multiple conditions from an array of objectsHello, I'm having trouble formulating a query that will match rows to multiple conditions at the samPostgres.js type error string/dateI'm running the following where clause in a select query:
```
.where(
and(
gt(
sql`${e.add a prefix to UUID?I am wondering if there is a functionality where I can add a custom prefix the uuid's. These uuids w[BUG?] Handling Postgresql schemas when using enums"drizzle-orm": "^0.30.10"
Hello. I have a simple table with a status column
```ts
export const BaseSHelp needed for Nested QueryFor this example, I have 4 tables - `user`, `podcast`, `episodes`, and `bookmarks`.
- bookmarks tablHow to init sqlite project?https://github.com/drizzle-team/drizzle-orm/issues/2240 ?Typescript performance in larger codebases?Hey, I've been using drizzle with small projects, but now I'm thinking of migrating a larger codebas