lelabo
lelabo
Explore posts from servers
TTCTheo's Typesafe Cult
Created by lelabo on 7/26/2024 in #questions
Handling Third-party lib client component that relies on ENV vars.
I understand, I already had the sentiment it was the only way to do it... But I did not understand why it wasn't as important with client side key.
24 replies
TTCTheo's Typesafe Cult
Created by lelabo on 7/26/2024 in #questions
Handling Third-party lib client component that relies on ENV vars.
But in environment when I don't control the components and the host (non-self-hosted content for example), I will have to make sure that this is handled correctly or find another solution.
24 replies
TTCTheo's Typesafe Cult
Created by lelabo on 7/26/2024 in #questions
Handling Third-party lib client component that relies on ENV vars.
I just read that most of the time, you also need to actually control from where comes the request when using client side key. The only bad design is to use them without ensuring who is actually using them.
24 replies
TTCTheo's Typesafe Cult
Created by lelabo on 7/26/2024 in #questions
Handling Third-party lib client component that relies on ENV vars.
Still, isn't leaking client side key bad practice ? That could still be used to impersonate my access to a service...
24 replies
DTDrizzle Team
Created by lelabo on 2/13/2024 in #help
How to drop a failed drizzle-kit push?
Did not understand really what happened BUT: I runned bun drizzle-kit introspect:mysql to download the DDL. I tried to bun drizzle-kit generate:mysql with this schema and I could see the changes it wanted to make. And from there I could see that it wanted to do some strange alter statements. Not wanting to deal with this on a dev branch, I just deleted my tables.
3 replies
DTDrizzle Team
Created by lelabo on 2/13/2024 in #help
How to drop a failed drizzle-kit push?
For more context: I am working with PlanetScale and always used dotenv drizzle-kit push:mysql to apply changes in the past. I read the documentation about the others command and try drop for example, but it seems I need to have an migration folder locally (I don't understand in my case where are the migration information stored). I did not try generate and introspect yet, in fear of f***ing everything up. I did not find information on how the two workflows are compatible/switchable.
3 replies
DTDrizzle Team
Created by roman910 on 11/12/2023 in #help
Duplicate indexes when using `serial('').primaryKey()`
The question I also have, which might help (or not): Can we redefine the default indexes in the schema? I checked the indexes for a junction table and instead of two separate indexes for each key, I am thinking of a multi index on the most important key and a simple index for the secondary one. This way, I cover all use-cases and query using both key (hmm, many-to-many join for example) should benefits from the multi index.
5 replies
DTDrizzle Team
Created by roman910 on 11/12/2023 in #help
Duplicate indexes when using `serial('').primaryKey()`
I just came to the same question myself... after digging to understand the default indexes for composite primary key and checking on a 'normal' table. Did you find any explaination?
5 replies
DTDrizzle Team
Created by lelabo on 1/7/2024 in #help
Relations with multiple fields and references, or with constraints.
This would address indeed some of the cases. Nice to see I am not just asking some dumb questions, but asking about things that actually are looked upon. In the mean time, I think joins will do the jobs...
9 replies
DTDrizzle Team
Created by lelabo on 1/7/2024 in #help
Relations with multiple fields and references, or with constraints.
I used polymorphic before but I did not think of this as a polymorphic relation, as I am not filtering on the same table. For me it was more like "relation meet filtering"
9 replies
DTDrizzle Team
Created by lelabo on 1/7/2024 in #help
Relations with multiple fields and references, or with constraints.
My schema look like this:
export const food = mysqlTable("food", {
id: serial("id").primaryKey(),
name: varchar("name", { length: 256 }),
});

export const foodRelations = relations(food, ({ one, many }) => ({
nutrients: many(foodNutrients),
}));

export const nutrients = mysqlTable("nutrient", {
id: serial("id").primaryKey(),
type: mysqlEnum("type", ["nutrition", "macro", "micro", "fodmap"]),
name: varchar("name", { length: 256 }),
});

export const nutrientRelations = relations(nutrients, ({ many }) => ({
foods: many(foodNutrients),
}));

export const foodNutrients = mysqlTable(
"food_nutrient",
{
foodId: bigint("foodId", { mode: "number" }).notNull(),
nutrientId: bigint("nutrientId", { mode: "number" }).notNull(),
value: bigint("value", { mode: "number" }).notNull(),
},
(table) => ({
pk: primaryKey(table.foodId, table.nutrientId),
}),
);

export const foddNutrientRelations = relations(foodNutrients, ({ one }) => ({
food: one(food, {
fields: [foodNutrients.foodId],
references: [food.id],
}),
nutrient: one(nutrients, {
fields: [foodNutrients.nutrientId],
references: [nutrients.id],
}),
}));
export const food = mysqlTable("food", {
id: serial("id").primaryKey(),
name: varchar("name", { length: 256 }),
});

export const foodRelations = relations(food, ({ one, many }) => ({
nutrients: many(foodNutrients),
}));

export const nutrients = mysqlTable("nutrient", {
id: serial("id").primaryKey(),
type: mysqlEnum("type", ["nutrition", "macro", "micro", "fodmap"]),
name: varchar("name", { length: 256 }),
});

export const nutrientRelations = relations(nutrients, ({ many }) => ({
foods: many(foodNutrients),
}));

export const foodNutrients = mysqlTable(
"food_nutrient",
{
foodId: bigint("foodId", { mode: "number" }).notNull(),
nutrientId: bigint("nutrientId", { mode: "number" }).notNull(),
value: bigint("value", { mode: "number" }).notNull(),
},
(table) => ({
pk: primaryKey(table.foodId, table.nutrientId),
}),
);

export const foddNutrientRelations = relations(foodNutrients, ({ one }) => ({
food: one(food, {
fields: [foodNutrients.foodId],
references: [food.id],
}),
nutrient: one(nutrients, {
fields: [foodNutrients.nutrientId],
references: [nutrients.id],
}),
}));
9 replies
TTCTheo's Typesafe Cult
Created by lelabo on 1/2/2024 in #questions
How to make scripts in a t3-stack app (with tsx and t3-env)?
For anyone looking for a solution... I managed to get it working after multiple try with the following setup: 1 - you will need the dotenv package 2 - my package.json look like this:
{
"name": "project",
"version": "0.1.0",
"private": true,
"type": "module",
"scripts": {
"build": "next build",
[...]
"tsx": "dotenv tsx",
"dev": "next dev --turbo",
"lint": "next lint",
"start": "next start"
},
[...]
}
{
"name": "project",
"version": "0.1.0",
"private": true,
"type": "module",
"scripts": {
"build": "next build",
[...]
"tsx": "dotenv tsx",
"dev": "next dev --turbo",
"lint": "next lint",
"start": "next start"
},
[...]
}
WIth this, I am able to run scripts with the following command: pnpm run tsx scripts/any-script.ts
4 replies
DTDrizzle Team
Created by Zack on 12/28/2023 in #help
Recommended place to add prepared statements
In my understanding, prepared statements are like queries but deferred to actual execute() calls. I would treat them like my other queries... I don't see why you would treat them otherwise. I would write them where it feels right writing your queries in your actual setup. For the other part, I am not an expert but I believe it is tied to your backend... Search prepared statement performance [postgres/MySQL/SQLite]
2 replies
DTDrizzle Team
Created by lelabo on 12/22/2023 in #help
Computed/derived fields in Drizzle Orm
- #1471: rarely had to use these. Usually, I ended up using the functionality to make raw queries and store the results in other variables. But it's nice to have... I had it in the past I think in some python ORM. - .default() like yeah, obviously, a classic. - #1513: I am not sure, I had it in the past, it's very powerful, but might complicates things and make them look harder than it need to be. But very cool, if they manage to do what's proposed at the end, not just validation. However, I was thinking about something much more simpler: Imagine having birthday stored in your dB, you want the age of the user for some calculation (maybe health subject)... I might do the calculation X times in different pages, I might do an helper to avoid repetition, but I could have a field generated after the fetch from the dB based on the birthday field. For more complicated fields, it allows to derive a state in a standardized way, which avoids errors made by multiple people working on the same codebase for example...
5 replies
DTDrizzle Team
Created by lelabo on 12/22/2023 in #help
Computed/derived fields in Drizzle Orm
Oh, thanks, forgot to watch issues on GitHub. Did my search here and in the docs...
5 replies
TTCTheo's Typesafe Cult
Created by Bozic0909 on 10/19/2022 in #questions
how to get next-auth session in _app.tsx on getInitalProps?
Did you try to use unstable_getServerSession() ? I am not sure if it works in _app.getInitalProps but that the recommended way to get a server side session. https://next-auth.js.org/configuration/nextjs#unstable_getserversession
6 replies