Using Prisma with the Electron Framework
See original GitHub issuePrisma Support for Electron
Electron is a framework for building cross-platform desktop apps with JavaScript, HTML, and CSS. While Electron can use similar frameworks and tooling as web applications, it (electron) has some differences that make it challenging to use with Prisma.
Existing problems
A (non-exhaustive) list of problems that should be addressed to improve the Electron experience with Prisma:
-
Difficult to generate Prisma Client on the fly for a schema:
- Related Issue: #9620
-
Certain data types (Currently
Bytes
andBigInt
) are unserializable and can’t be passed to the renderer process throughIPC
- Related Issue: #9661
Solved Problems
- Can not spawn
Query Engine
binary when using Prisma with Electron:- Related Issue: #9619
Related Discussions and Issues on Github
- Make Prisma Client (usage + generation) ASAR compatible
- Electron Integration Best Practise
- ASAR error when used with Electron
Acknowledgement: Big thanks to @madebysid for his help in researching this issue.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:20
- Comments:8 (3 by maintainers)
Top Results From Across the Web
How to use Prisma with Electron - Stack Overflow
Solution. import { PrismaClient } from './generated/client'; As the downloaded binaries are also placed indside the output folder, there was no ...
Read more >Running Prisma migrate in an Electron app
I use Prisma Migrate in my Electron app. Here's a mechanism to detect when I need to run migrations on app start.
Read more >Quickstart with TypeScript & SQLite - Prisma
Quickstart · 1. Create TypeScript project and set up Prisma · 2. Model your data in the Prisma schema · 3. Run a...
Read more >@prisma/studio-electron - npm
Modern Database IDE. Latest version: 0.426.0, last published: a year ago. Start using @prisma/studio-electron in your project by running ...
Read more >Learn Electron, Jwt and Prisma - Egghead.io
Build a Backend with Prisma in a TypeScript Node Project. Ryan Chenkie ... JSON Web Token (JWT) Authentication with Node.js and Auth0. Joel...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
Top Related Hashnode Post
No results found
@sinclairnick The most common use I have seen is to ship an SQLite Database with the electron app. This is done to ensure local data persistence and to support features for apps that need to work in offline mode, just to name a use-case.
I’m using it as Tasin says, to manage a SQLite database. Here are a few issues I encountered:
prisma migrate deploy
, it needs the Prisma binaries (query engine, migration engine) included. The size of the binaries on Windows is 70MB and similar on Mac and Linux.extraResources
property of electron-builder and excluding them fromfiles
. At first I tried usingasarUnpack
, but that lead to the binaries getting placed in bothapp.asar
andapp.asar.unpacked
, which doubles the space they take.prisma migrate deploy
on app start. However the only way to do that currently is fork a new process, since it’s a CLI. Related issue: https://github.com/prisma/prisma/issues/4703I have Prisma working fine on Windows, Mac, and Linux in my Electron app. But I had to figure out the above issues. Happy to talk with anyone who wants to try the same.
Appendix
Here’s my code for running
prisma migrate deploy
programmatically, in case anyone else is trying to do the same:Code for working around slow Prisma client instantiation