MC_2018
MC_2018
Explore posts from servers
DTDrizzle Team
Created by MC_2018 on 11/15/2024 in #help
How to delete multiple db entries at once?
I have a list of IDs of items I wish to delete, but I cannot figure out a way to delete them. I would prefer not to use hard-coded SQL as that's why I chose to use Drizzle over other alternatives. Here is what I have and what I found, but does not appear to work. I could not find any IN function built into Drizzle. Any help would be much appreciated.
// tagTable: my defined DB table schema
// tagsToRemove: a list of Tags
class Tag {
tagId: number
}

await db.delete(tagTable).where(sql`${tagTable.tagId} IN (${sql.join(tagsToRemove.map(x => x.tagId))})`);
// tagTable: my defined DB table schema
// tagsToRemove: a list of Tags
class Tag {
tagId: number
}

await db.delete(tagTable).where(sql`${tagTable.tagId} IN (${sql.join(tagsToRemove.map(x => x.tagId))})`);
2 replies
CC#
Created by MC_2018 on 12/29/2023 in #help
DbContext with IServiceProvider: whether or not to have a using statement
Hello, I have a straightforward question regarding using a DbContext from IServiceProvider. I'm aware that traditionally, when creating a DbContext, you should have a using statement; is this still needed when using the IServiceProvider?
using var context = Program.ServiceProvider.GetRequiredService<ShuffullContext>();
using var context = Program.ServiceProvider.GetRequiredService<ShuffullContext>();
Or does the IServiceProvider handle disposal and no longer require it?
var context = Program.ServiceProvider.GetRequiredService<ShuffullContext>();
var context = Program.ServiceProvider.GetRequiredService<ShuffullContext>();
3 replies
CC#
Created by MC_2018 on 1/26/2023 in #help
❔ Locally-hosting my site, cannot view on phone (MVC)
18 replies