postgresql-dart icon indicating copy to clipboard operation
postgresql-dart copied to clipboard

Not usable via Web/compiled to JS

Open dominickj-tdi opened this issue 5 years ago • 3 comments

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.

dominickj-tdi avatar Jun 12 '19 17:06 dominickj-tdi

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....

isoos avatar Jun 12 '19 18:06 isoos

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?

dominickj-tdi avatar Jun 12 '19 19:06 dominickj-tdi

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.

isoos avatar Jun 12 '19 19:06 isoos