pglite icon indicating copy to clipboard operation
pglite copied to clipboard

Rust Bindings

Open callum-gander opened this issue 11 months ago • 18 comments

Are there any future plans to add Rust bindings for this? I can see this as an appealing alternative to bundling up Postgres as a sidecar for things like Tauri apps or using SQLite. Thanks

callum-gander avatar Dec 14 '24 09:12 callum-gander

Are there any future plans to add Rust bindings for this? I can see this as an appealing alternative to bundling up Postgres as a sidecar for things like Tauri apps or using SQLite. Thanks

Maybe you could try using pglite directly within Tauri’s webview? I’m not sure if it will work, but it could be an interesting alternative to bundling Postgres as a sidecar.

realmorrisliu avatar Dec 18 '24 02:12 realmorrisliu

That doesn't feel very secure imo, feels like it should sit on the rust side rather than in the webview, but appreciate the idea

callum-gander avatar Dec 29 '24 14:12 callum-gander

Not keen on Rust, but maybe a valid approach would be to just run pglite inside rust with https://docs.wasmtime.dev/lang-rust.html like it was done for Go here https://github.com/electric-sql/pglite/issues/89

To go further than that POC you would need to pick a rust postgres wire protocol client crate though.

pmp-p avatar Jan 10 '25 15:01 pmp-p

Besides wasm, can pglite also build to native code? Getting Rust to run regular wasm pglite would be awesome, but the downside is that it would still require a wasm runtime. Embedding a native build of pglite as a library in a Rust program would be very useful, if at all possible.

Right now what exists in Rust for "embedding" Postgres is pg_embed and postgresql-embedded. They can use native binaries from embedded-postgres-binaries (which is a trimmed down Postgres made for testing SQL queries in the Java ecosystem), or, in the case of postgresql-embedded, also from postgresql-binaries. pg_embed downloads the Postgres binary in the first run, and postgresql-embedded can also do that, but can package the Postgres binary inside its own binary to make distribution easier, extract it somewhere in the first run either way - Postgres still runs as a separate program. An upside for postgresql-embedded is that it supports Postgres extensions though.

dlight avatar Apr 26 '25 20:04 dlight

Besides wasm, can pglite also build to native code?

Not yet, but we'd like it to. See the last part of this comment.

tdrz avatar Apr 27 '25 12:04 tdrz

Super excited for libpglite to come!

realmorrisliu avatar Apr 28 '25 03:04 realmorrisliu

Besides wasm, can pglite also build to native code?

Not yet, but we'd like it to. See the last part of this comment.

native rust would be huge for me- any idea on when this will be coming?

evanlhatch avatar May 17 '25 02:05 evanlhatch

i think the correct way -now- would be to embded wasmtime. Only wasm sandboxing can offer safety that would be lost by compiling pglite as transpiled rust and/or unsafe C library.

Wasmtime embedding is quick, easy and ultra portable. Any other mean would probably be only possible as a long term project.

pmp-p avatar Aug 04 '25 17:08 pmp-p

Why is wasmtime the way to go?

We want to extract the core changes to Postgres that we had to make and create a "libpglite" C lib that can be linked to from any language/platform.

Taken from: https://news.ycombinator.com/item?id=41225185

Wouldn't a libpglite be the most preferable way?

unsafe C library.

Wouldn't any issues be handled the rust side?

paulm17 avatar Aug 06 '25 14:08 paulm17

I'd love a working example to work off on if anyone has gotten wasmtime + pglite wasm file working.

TheKnarf avatar Aug 28 '25 13:08 TheKnarf

I was able to get some basic stuff working for rust and wasmtime here: pglite-oxide

f0rr0 avatar Sep 27 '25 02:09 f0rr0

@f0rr0 super cool. what are current limitations?

yujonglee avatar Sep 27 '25 02:09 yujonglee

@yujonglee you can run a unix/tcp socket and talk over wire protocol. or you can use the CMA channel and read/write command inputs/outputs. I also include the vector extension and pgdump. I am currently using it in my tauri desktop app so I guess I will eventually find out the limitations.

f0rr0 avatar Sep 27 '25 02:09 f0rr0

@f0rr0 Thanks for putting this together. Would be nice if the ReadMe could have a section for Tauri integration! 😄

paulm17 avatar Sep 27 '25 08:09 paulm17

Yes I’ll be adding that soon once I successfully integrate and run the whole thing

On Sat, 27 Sep 2025 at 2:15 PM, Paul @.***> wrote:

paulm17 left a comment (electric-sql/pglite#470) https://github.com/electric-sql/pglite/issues/470#issuecomment-3341411701

@f0rr0 https://github.com/f0rr0 Thanks for putting this together. Would be nice if the ReadMe could have a section for Tauri integration! 😄

— Reply to this email directly, view it on GitHub https://github.com/electric-sql/pglite/issues/470#issuecomment-3341411701, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACBNKC7FXWF4GVHACPZM5LD3UZFDFAVCNFSM6AAAAABTTLFAUGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZTGNBRGQYTCNZQGE . You are receiving this because you were mentioned.Message ID: @.***>

f0rr0 avatar Sep 27 '25 08:09 f0rr0

any updates on how to use with Tauri?

roo12312 avatar Nov 12 '25 06:11 roo12312