Created
September 15, 2023 18:15
-
-
Save riandoza/acc561160280b0fca068fd82c11da229 to your computer and use it in GitHub Desktop.
Prisma SQLite Bulk Insert or Update
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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