Skip to content

Instantly share code, notes, and snippets.

@riandoza
Created September 15, 2023 18:15
Show Gist options
  • Save riandoza/acc561160280b0fca068fd82c11da229 to your computer and use it in GitHub Desktop.
Save riandoza/acc561160280b0fca068fd82c11da229 to your computer and use it in GitHub Desktop.
Prisma SQLite Bulk Insert or Update
const domains = ['google.com','github.com','instagram.com'];
/*** Method 1 ***/
const upsertManyDomains = domains.map((post) =>
prisma.domains.upsert({
where: { domain: post.trim() },
create: {
domain: post.trim(),
},
update: {
domain: post.trim(),
status: "success",
},
}),
);
Promise.all(upsertManyDomains);
/*** Method 2 ***/
let upsertManyDomains = [];
for (const post of domains) {
upsertManyDomains.push(
prisma.domains.upsert({
where: {
domain: post.trim(),
},
update: {
domain: post.trim(),
status: "success",
},
create: {
domain: post.trim(),
},
})
);
}
await prisma.$transaction(upsertManyDomains);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment