SkylerLipthay / mini-v8

A minimal embedded V8 JavaScript engine wrapper for Rust
MIT License
104 stars 11 forks source link

Could MiniV8 be used as a Postgres extension to add JS support, similar to PLV8? #5

Closed GavinRay97 closed 11 months ago

GavinRay97 commented 3 years ago

Might be a silly question, but this project is really cool, and I was curious whether it would be (theoretically) possible to use it as a native extension for executing JS from Postgres, like PLV8 but Rust rather than C++ :slightly_smiling_face:

SkylerLipthay commented 3 years ago

Thank you! I've never written a Postgres extension but I don't see why PLV8 couldn't be replicated using this library as a basis, but it seems like it would be quite a roundabout path, seeing as both V8 and the Postgres extension framework are natively C/++.

Interestingly my original motive for experimenting with embedded JS engines in Rust was to replace relational databases (Postgres specifically) entirely in some of my applications. Right now I'm using this library to provide a user-facing scripting engine for my Rust web app that interfaces with plain old in-memory Rust types (occasionally serialized to the file system by a serde-like library) instead of a Postgres database. Great for "small" (under ~10 GB) data.

In general I think the application pattern of the "scripting interface" is underappreciated. V8 is not exactly lightweight, but its world-class performance combined with the widespread familiarity with JavaScript allows for some potentially awesome applications.

GavinRay97 commented 3 years ago

That's an interesting concept actually -- I have a friend building a platform that's doing fairly well, and the datastore + job system run on nothing but a hierarchical directory of folders with JSON files haha. You can go quite far with minimal infrastructure burden it seems :+1:

(I'm all for this approach when it fits, though I'd use SQLite and JSON columns if I needed schemaless/dynamic data personally. SQLite is massively undervalued).

Slightly off tangent, but there's a group of Ph. D's from the Database Architectures Group in NL that have been working on an in-memory blindingly fast columnar DB that's pretty neat (still relational though). If that sounds interesting, here's the link: https://duckdb.org/

It seems like it would be quite a roundabout path, seeing as both V8 and the Postgres extension framework are natively C/++

There are a couple of frameworks which provide really, really nice Rust API's for writing native PG extensions (compared to the C you'd have to write, it's :heart_eyes:)

https://github.com/zombodb/pgx https://github.com/bluejekyll/pg-extend-rs

And there's the WASMer one as well, which supports WASM libraries/binaries as extensions:

https://github.com/wasmerio/postgres-ext-wasm

But yeah, at the end of the day it would be a big layer of Rust wrapping C++. I guess I only asked because it seemed like a Rust port of PLV8 would be cleaner than the C++ implementation currently.

I don't have a lot of background context/understanding, so my naive question was basically "Can you somehow take MiniV8 and pgx for PG extensions and redo PLV8?"

Thanks for the response though =D