lelabo
lelabo
Explore posts from servers
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
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