stablekernel / postgresql-dart

Dart PostgreSQL driver: supports extended query format, binary protocol and statement reuse.
https://www.dartdocs.org/documentation/postgres/latest
BSD 3-Clause "New" or "Revised" License
127 stars 32 forks source link

Not usable via Web/compiled to JS #100

Open dominickj-tdi opened 5 years ago

dominickj-tdi commented 5 years ago

I'm primarily a web developer, though I prefer Dart over Javascript. I thought I'd try my hand at a desktop app using Dart and Electron, with PostgreSQL as the data storage. However, when I try to open a connection to my database, I get "unsupported operation: socket constructor".

After some searching around on the internet, I came across this StackOverflow answer which indicates that you can't connect to PostgreSQL via dart for the web. Which would obviously also exclude Electron since it's basically just the Chromium browser. https://stackoverflow.com/a/34605154/1941632

I'm not sure if this is something that would be possible to add, or if the issue is because of PostgreSQL itself. But if it's not too difficult to add, that would be awesome to have.

If not, no worries. I'm by no means married to using Electron at this point. I'll just have to find a different way to build the UI.

isoos commented 5 years ago

Connecting directly to a Postgresql server from the browser is a bad idea: connection username and password is easy to extract, and with that, people have open access to your database server.

I believe Electron has a server component, and the browser component talks to that instead of the Postgresql server. A similar setup should be used for most use cases....

dominickj-tdi commented 5 years ago

Fair point, in a regular web app that would definitely be a bad idea. In my case PostgreSQL would be running either on localhost or just a computer on the LAN, so for this particular application I'm not too worried about the user knowing the credentials for the server. Be I certainly see your point, for general application that would be basically begging people to hack your database.

Just a question though: The server component in Electron is based on Node.js, so it also has to be compiled to Javascript. Wouldn't it have the same problem?

isoos commented 5 years ago

I have no idea if/how mixing Electron and Dart would work out. I mostly do Dart server-side and some Dart client-side stuff, I cannot comment on how the integration would look like.