Is it feasible to use prisma client in the browser against sqlite compiled to webassembly #18428
|
Hello. My project uses Prisma with sqlite on the backend already, and we're quite happy with it. I'm now working on implementing offline support in our client, and it occurred to me that it'd be great to be able to reuse some of our schema between the client and the server (or at least get to use some of prisma's awesome features in both places if schema can't be shared). I'm looking for a sanity check that this is even possible today, and if it is, guidance on where to start. I see that the official sqlite project has support for running in the browser with webassembly and storage provided by localstorage. We've already got a monorepo set up that allows us to share JS code successfully between the client and server. If this idea isn't possible today, perhaps this post can be a place of discussion for what it might take to make it possible in the future, and whether the project is interested in doing so. |
Replies: 7 comments 5 replies
|
Prisma currently can not do that, as we do not compile the full engines to Wasm. |
|
considering prisma 7 client is rust free, i believe it should be possible to use prisma in the browser now |
|
I ran into this same problem and ended up building a generator for it — prisma-idb. It uses IndexedDB as the storage layer instead of SQLite/WASM, but gives you the same Prisma Client API in the browser, generated from your existing schema. Supports findMany, include, nested writes, etc. If you specifically need SQLite semantics or raw SQL, it won't fit. But if the goal is Prisma API + offline storage + optional bidirectional sync, it might be worth a look. |
|
Prisma has a WASM query builder and now makes this practical, so we published: @row-chat/prisma-sqlite-wasm-adapter, an in-browser Prisma adapter for @sqlite.org/sqlite-wasm.
How it works: the sqlite-wasm DB lives in a SharedWorker (so all tabs on the same origin see the same database). Queries like prisma.album.findMany() work entirely in the browser. |
|
We also have working in-browser adapters for wa-sqlite and PGLite that we plan to publish in the future. |
|
The Prisma adapter for wa-sqlite has been published: https://www.npmjs.com/package/@row-chat/prisma-wa-sqlite-adapter |
|
PGLite can be used with Prisma in the browser without extra dependencies. Here are the instructions. With the plain PGLite Prisma adapter each browser tab uses a full instance of PGLite. In the future the package described in this link will be published to enable one instance of PGLite to coordinate through a SharedWorker: https://github.com/row-chat/prisma-browser-adapters/tree/main/packages/prisma-pglite-adapter#readme |
Prisma currently can not do that, as we do not compile the full engines to Wasm.
Attempting this is also not a priority right now, as we are quite busy with Node as a environment - we won't add browser to our workload here at least this year.