logoalt Hacker News

afavouryesterday at 4:21 PM3 repliesview on HN

What would a Node-native database connection layer look like? What other platforms have that?

Databases are third party tech, I don’t think it’s unreasonable to use a third party NPM module to connect to them.


Replies

mike_hearnyesterday at 4:31 PM

Most obviously, Java has JDBC. I think .NET has an equivalent. Drivers are needed but they're often first party, coming directly from the DB vendor itself.

Java also has a JIT compiling JS engine that can be sandboxed and given a VFS:

https://www.graalvm.org/latest/security-guide/sandboxing/

N.B. there's a NodeJS compatible mode, but you can't use VFS+sandboxing and NodeJS compatibility together because the NodeJS mode actually uses the real NodeJS codebase, just swapping out V8. For combining it all together you'd want something like https://elide.dev which reimplemented some of the Node APIs on top of the JVM, so it's sandboxable and virtualizable.

show 1 reply
pier25yesterday at 4:34 PM

Bun provides native MySQL, SQlite, and Postgres drivers.

I'm not saying Node should support every db in existence but the ones I listed are critical infrastructure at this point.

When using Postgres in Node you either rely on the old pg which pulls 13 dependencies[1] or postgres[2] which is much better and has zero deps but mostly depends on a single guy.

[1] https://npmgraph.js.org/?q=pg

[2] https://github.com/porsager/postgres

show 2 replies
ksherlockyesterday at 4:29 PM

Perl has DBI. PHP has PDO.

show 1 reply