DT
Drizzle Teammakaron pelnoziarnisty

Delete limit

Hi, how do I delete just 1 row from a table?
// Example:
db.delete(dogs).where(eq(dogs.breed, 'husky')).limit(1)
// Example:
db.delete(dogs).where(eq(dogs.breed, 'husky')).limit(1)
NinjaBunny
NinjaBunny319d ago
you can pass in the id of the specific dog you’d like to delete so where dog is husky AND dogId is …. you have to be more specific if you want the query to only delete 1 row
makaron pelnoziarnisty
makaron pelnoziarnisty319d ago
yeah but Id need to make a query first right? No other way to do it with just one query rn?
NinjaBunny
NinjaBunny319d ago
well it depends, how are you getting to the point of I want to delete 1 dog certainly that dog’s data will have everything necessary for us to delete it if we so choose
makaron pelnoziarnisty
makaron pelnoziarnisty319d ago
um, im not sure what you mean I just want to delete any dog of the given breed Can I do better than this?:
// I suppose it is more beneficial to wrap it up in a transaction function
await db.transaction(async (tx) => {
const dog = await tx.query.dogs.findFirst({
where: (dogs, { eq }) => eq(dogs.breed, 'husky')
});

await db.delete(dogs).where(eq(dogs.id, dog.id));
});
// I suppose it is more beneficial to wrap it up in a transaction function
await db.transaction(async (tx) => {
const dog = await tx.query.dogs.findFirst({
where: (dogs, { eq }) => eq(dogs.breed, 'husky')
});

await db.delete(dogs).where(eq(dogs.id, dog.id));
});
NinjaBunny
NinjaBunny319d ago
if you want to delete just 1 dog without any thought into which dog gets deleted this is prob the best approach
Want results from more Discord servers?
Add your server
More Posts
Many to many - PlanetscaleAnyone here has an example of declaring many to many relationship when using Planetscale? https://orInserting with RelationHi, What is the way of inserting a new record with a relationship in Drizzle. I understand that Prisql escaping on whereTrying to do the following: ``` where: sql`unaccent(${users.fullName}) ILIKE unaccent('%${input.queBroken typescript in selectWhatever I put inside the select function. it will generate this typescript error: I am using the laWhy is introspecting creating tables that didn't previously existMore context here: https://github.com/drizzle-team/drizzle-orm/issues/847Passing SQL functions to insertIs there any way to pass a SQL function like `gen_random_uuid()` to the `insert` function, for a speDrizzle-kit database push connection errorWhen trying to run `drizzle-kit push:mysql` to push my schema to Planetscale, I get the following erTypescript error when importing the planetscale-drizzle db instance.my db is hosted on planetscale and im trying to do the setup as explained in the drizzle docs but whMapped column name and relation with the original nameHi, I am taking over an old project and have found an issue, I'm not sure if I should file it as a bHow to properly do foreign keys in schema with PlanetScale?I'm aware that foreign key *constrains* aren't supported, but foreign keys themselves are. push: ``Typescript path alias not working properlyI'm new to Drizzle, but I'm not able to use the path alias on schema files. Using absolute paths onExpand query from ID using .select()Hi! I am trying to get the first name of a comment author, but only store the ID so the user can chaPGEnum -> Typescript EnumHey there. Is there any convenient way people have found to conveniently turn a pgEnum into a typescIs Drizzle Kit/Drizzle Studio possible with RDS Data API?I'm able to create the RDSDataClient for querying my DB using Drizzle ORM, but I don't see a way to How to apply migrations on postgres in a serverless enviroment?Hello, I want to apply postgres migrations to my vercel DB. I see that the push command does not woError when trying to generate a migration schemaanyone any ideas to what the problem is? It was working fine yesterday and now it throws an error whModelling self relationsI have a table `categories` with a parent fields: ``` { id: text("id").notNull().primaryKey(), .Issue running migrations to DBI am having an issue running migrations to Neon. I checked that everything is exporting const variabIt is possible to have prepared statements inside transactions?Is there a way to insert prepared queries inside a transaction ?type config findMany or findFirstHi, I've one question i don't find the way to type correctly findMany() Like: export async function