lelabo
lelabo
Explore posts from servers
DTDrizzle Team
Created by lelabo on 7/18/2024 in #help
Insert line break in Postgres
I am trying to insert line breaks ('\n') into a text field in Postgres. I saw that I am supposed to do the following: https://stackoverflow.com/questions/36028908/postgresql-newline-character I would like to know if folks here have a solution without making a raw query to the database each time one of the field may store line breaks?
2 replies
DTDrizzle Team
Created by lelabo on 2/13/2024 in #help
How to drop a failed drizzle-kit push?
Hi, I made some changes to table (transformed some bigint("id", { mode: "number" }).notNull() to bigint("id", { mode: "number" }).primaryKey()). I tried to apply my changes with bun run dotenv drizzle-kit push:mysql as usual... And I got some errors:
Error: target: snacs.-.primary: vttablet: rpc error: code = Unknown desc = Check constraint 'id' is not found in the table. (errno 3821) (sqlstate HY000) (CallerID: q7b5b4s79a6trurkk7ej): Sql: "alter table snacs_food_attribute drop check id", BindVars: {REDACTED}
at PromiseConnection.query (/home/lelabo/DEV/SNACS/willitfodmap/node_modules/drizzle-kit/index.cjs:35481:26)
at Command.<anonymous> (/home/lelabo/DEV/SNACS/willitfodmap/node_modules/drizzle-kit/index.cjs:53292:33)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: undefined,
errno: 3821,
sql: 'ALTER TABLE `snacs_food_attribute` DROP CONSTRAINT `id`;',
sqlState: 'HY000',
sqlMessage: `target: snacs.-.primary: vttablet: rpc error: code = Unknown desc = Check constraint 'id' is not found in the table. (errno 3821) (sqlstate HY000) (CallerID: q7b5b4s79a6trurkk7ej): Sql: "alter table snacs_food_attribute drop check id", BindVars: {REDACTED}`
}
Error: target: snacs.-.primary: vttablet: rpc error: code = Unknown desc = Check constraint 'id' is not found in the table. (errno 3821) (sqlstate HY000) (CallerID: q7b5b4s79a6trurkk7ej): Sql: "alter table snacs_food_attribute drop check id", BindVars: {REDACTED}
at PromiseConnection.query (/home/lelabo/DEV/SNACS/willitfodmap/node_modules/drizzle-kit/index.cjs:35481:26)
at Command.<anonymous> (/home/lelabo/DEV/SNACS/willitfodmap/node_modules/drizzle-kit/index.cjs:53292:33)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: undefined,
errno: 3821,
sql: 'ALTER TABLE `snacs_food_attribute` DROP CONSTRAINT `id`;',
sqlState: 'HY000',
sqlMessage: `target: snacs.-.primary: vttablet: rpc error: code = Unknown desc = Check constraint 'id' is not found in the table. (errno 3821) (sqlstate HY000) (CallerID: q7b5b4s79a6trurkk7ej): Sql: "alter table snacs_food_attribute drop check id", BindVars: {REDACTED}`
}
So, I revert the changes, and try again to push some very minor change to another table to check if everything is ok. And I still get the same error. I don't know how I am supposed to drop the current cached mutation.
3 replies
DTDrizzle Team
Created by lelabo on 1/7/2024 in #help
Relations with multiple fields and references, or with constraints.
Lets say I have a table food and a table nutrient. The food table contains an id and a name. The nutrient table contains an id, a type and a name. I want to create a many-to-many relation about the food to their nutrients, so I did a third table: food-nutrient. The food-nutrient table as a foodId, a nutrientId and for now an amount. This setup seems to be doable with the many-to-many example, I did it just fine... I can now query food.foodNutrients and food.foodNutrients[number].nutrient. NOW, lets say, I want food.macros and food.micros which are the same relations but with a new constraint on nutrient.type. Is it doable and how? In MySQL, I would do this with a join (like the following) but I would rather use a relation if possible:
SELECT * FROM food_nutrient
JOIN nutrient ON nutrient.id = food_nutrient.nutrientId
WHERE foodId = 1 AND type = 'macro';
SELECT * FROM food_nutrient
JOIN nutrient ON nutrient.id = food_nutrient.nutrientId
WHERE foodId = 1 AND type = 'macro';
I saw that relation accept arrays in one function config arg for fields and references, I am playing with it right now, but did not figure how to do it yet, I would like to be able to specify something like a where.
9 replies
DTDrizzle Team
Created by lelabo on 12/22/2023 in #help
Computed/derived fields in Drizzle Orm
Hi, I am new to Drizzle, so sorry if it is a stupid question, but while picking it up, browsing the docs, etc... I noticed something missing I had normally with many other ORMs in the past: computed fields (as Prisma call them, for example as what I mean). I don't know if I missed something, I didn't find an explanation in the introduction/philosophy of the docs... but I would like to know what the recommended path here and the stance of Drizzle on the subject (is it not implemented yet, not a desired feature because of complexity, performance, etc). I know I can always derive these states as I need them, but It is an approach I have seen in most ORM I used, so I am curious to know why, how, and all.
5 replies