jhechtf
jhechtf
Explore posts from servers
DTDrizzle Team
Created by Kapatid on 2/16/2024 in #help
AWS Data API 'PROFILE'
If, however, you have another credential in that file you would like to use instead, you would simply supply that name instead by either setting the appropriate PROFILE environment variable, or hard-coding the name (not recommended)
4 replies
DTDrizzle Team
Created by Kapatid on 2/16/2024 in #help
AWS Data API 'PROFILE'
Hello, not part of the drizzle team but I was curious after reading this question so figured I'd respond with some guidance. The PROFILE env variable is which profile you would like to use the credentials of when connecting your to your RDS instance. This requires you to have setup an AWS credentials file at ~/.aws/credentials If you have logged in / used the AWS cli locally you should be able to run cat ~/.aws/credentials and unless I am mistaken you would use any of the values in the [], so if you have a [defaut] entry you would use default as the value. It also states that if the profile value is not specified it defaults to env.AWS_PROFILE or default in case the AWS_PROFILE is not available.
4 replies
DTDrizzle Team
Created by jhechtf on 1/18/2024 in #help
.query.with relationship types don't work unless I manually type them out
Ah, i must have missed that in the docs -- the dangers of reading fast. I had assumed i could split up the relations calls and as long as they were in the schema everything would work fine. Glad I finally got an answer!
24 replies
DTDrizzle Team
Created by jhechtf on 1/18/2024 in #help
.query.with relationship types don't work unless I manually type them out
Hopefully this is enough but LMK if you need something else to help debug https://github.com/jhechtf/drizzle-orm-issue
24 replies
DTDrizzle Team
Created by jhechtf on 1/18/2024 in #help
.query.with relationship types don't work unless I manually type them out
Sure, give me a bit to get a repo up and going.
24 replies
DTDrizzle Team
Created by jhechtf on 1/18/2024 in #help
.query.with relationship types don't work unless I manually type them out
will do some work to try and move the relationships around so that i can have 1 relationship call per table to see if that still works, but would definitely like to be able to split things up if possible.
24 replies
DTDrizzle Team
Created by jhechtf on 1/18/2024 in #help
.query.with relationship types don't work unless I manually type them out
To note though, using with still works, but now the return type is incorrect, and I have to read through the files to remember the corresponding name, which is suboptimal.
24 replies
DTDrizzle Team
Created by jhechtf on 1/18/2024 in #help
.query.with relationship types don't work unless I manually type them out
Ok so I think I've found the source, though in fairness I don't understand. I had split up the relationships based on the places where they sort of occurred. e.g. households <-> bills <-> payments, so in the payments.table.ts file I would setup the relationships pertaining to the payments table in there, e.g.
// payments.table.ts
import { bills } from './bills.table';
export const payments = pgTable(...);
export const paymentToBill = relations(payments, ({ one }) => ({
bill: one(bills, {
fields: [payments.billId],
references: [bills.id],
}),
}));

export const billsToPayments = relations(bills, ({ many }) => ({
payments: many(payments),
}));
// payments.table.ts
import { bills } from './bills.table';
export const payments = pgTable(...);
export const paymentToBill = relations(payments, ({ one }) => ({
bill: one(bills, {
fields: [payments.billId],
references: [bills.id],
}),
}));

export const billsToPayments = relations(bills, ({ many }) => ({
payments: many(payments),
}));
Which also meant that in say, the bills.table.ts file I was doing something similar
// bills.table.ts
import { households } from './households.table';
export const bills = pgTable(...);
export const billToHousehold = relations(bills, ({ one }) => ({
household: one(households, {
fields: [bills.householdId],
references: [households.id],
}),
}));
// bills.table.ts
import { households } from './households.table';
export const bills = pgTable(...);
export const billToHousehold = relations(bills, ({ one }) => ({
household: one(households, {
fields: [bills.householdId],
references: [households.id],
}),
}));
What I've noticed is that the moment the schema includes more than 1 relations() call on the same table, the type hinting goes out the window.
24 replies
DTDrizzle Team
Created by jhechtf on 1/18/2024 in #help
.query.with relationship types don't work unless I manually type them out
im at work rn so i can't spend too much time trying to get it working. will update later once i can spend more time on it
24 replies
DTDrizzle Team
Created by jhechtf on 1/18/2024 in #help
.query.with relationship types don't work unless I manually type them out
Doesn't appear to be fixing it right now.
24 replies
DTDrizzle Team
Created by jhechtf on 1/18/2024 in #help
.query.with relationship types don't work unless I manually type them out
I'm using a singular db schema -- using supabase auth so i setup a barebones drizzle schema + table to be able to use foreign keys.
24 replies
DTDrizzle Team
Created by jhechtf on 1/18/2024 in #help
.query.with relationship types don't work unless I manually type them out
unclear what you mean by that. are you talking about things like "schemaName"."tableName" or are you talking about the schema option when making a drizzle adapter?
24 replies
DTDrizzle Team
Created by jhechtf on 1/18/2024 in #help
.query.with relationship types don't work unless I manually type them out
No description
24 replies
DTDrizzle Team
Created by jhechtf on 10/12/2023 in #help
TS Types when using schema and "with"
what's weird for me is that i'm not getting any type inference on the result at all, even just one layer deep, which is weird because it used to and then just stopped didn't anymore.
18 replies
DTDrizzle Team
Created by jhechtf on 10/12/2023 in #help
TS Types when using schema and "with"
For reference: https://orm.drizzle.team/docs/rqb
You can chain nested with statements as much as necessary. For any nested with queries Drizzle will infer types using Core Type API. Get all users with posts. Each post should contain a list of comments
Code snippet under that
const users = await db.query.users.findMany({
with: {
posts: {
with: {
comments: true,
},
},
},
});
const users = await db.query.users.findMany({
with: {
posts: {
with: {
comments: true,
},
},
},
});
18 replies
DTDrizzle Team
Created by jhechtf on 10/12/2023 in #help
TS Types when using schema and "with"
it is in the docs, so i figured it was ok, issue i have now is that it's not even working for even first level.
18 replies
DTDrizzle Team
Created by jhechtf on 10/12/2023 in #help
TS Types when using schema and "with"
yeah I'm not entirely sure what I should be doing differently here -- it seems like these queries should have the types show up, they just don't.
18 replies
DTDrizzle Team
Created by jhechtf on 10/12/2023 in #help
TS Types when using schema and "with"
In testing a bit more, it seems like the issue is more "queries that use with inside another with" -- the types for anything below the initial "with" don't look like they're picked up. e.g.
const householdsValue = await db.query.usersToHouseholds.findMany({
where: ({ userId }, { eq }) => eq(userId, user.id),
with: {
household: {
with: {
users: true,
}
},
}
});

console.info(householdsValue[0].users); // <- red squiggles of doom
const householdsValue = await db.query.usersToHouseholds.findMany({
where: ({ userId }, { eq }) => eq(userId, user.id),
with: {
household: {
with: {
users: true,
}
},
}
});

console.info(householdsValue[0].users); // <- red squiggles of doom
18 replies